docker存储

目录挂载

[root@192 ~]# docker run -d --name app01 -p 80:80 -v /root/nginxhtml:/usr/share/nginx/html 9bbf2937ac71
35733ef692f3c6e169a003cfb77f47e364e3526fe38c735fc7e1e02c504f92c9
[root@192 ~]# ll
总用量 133992
-rw-------. 1 root root      1404 826 20:39 anaconda-ks.cfg
-rw-------. 1 root root 137201664 827 15:07 mynginx.tar
drwxr-xr-x. 2 root root         6 827 21:11 nginxhtml

[root@192 nginxhtml]# ll
总用量 0

此时以外部的nginxhtml的内容为准

在这里插入图片描述

在外部创建index.html

[root@192 nginxhtml]# echo 22222 > index.html
[root@192 nginxhtml]# ll
总用量 4
-rw-r--r--. 1 root root 6 827 21:21 index.html

在这里插入图片描述

从容器内部修改index.html

[root@192 nginxhtml]# docker exec -it 35733ef692f3 bash
root@35733ef692f3:/#
root@35733ef692f3:/#
root@35733ef692f3:/# cd /usr/share/nginx/html/
root@35733ef692f3:/usr/share/nginx/html# ls
index.html
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html# echo 3333 >> index.html
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html#
root@35733ef692f3:/usr/share/nginx/html# cat index.html
22222
3333

在这里插入图片描述

外部的文件同样也自动修改了

[root@192 nginxhtml]# cat index.html
22222
3333

卷映射

和目录挂载不同的是,卷映射在创建容器时直接同步容器内部的目录下数据到外部固定位置

创建容器

docker run -d --name app02 -v nginxconf:/etc/nginx -p 88:80 9bbf2937ac71

nginxconf是卷名

[root@192 nginxhtml]# docker run -d --name app02 -v /root/nginxhtml:/usr/share/nginx/html -v nginxconf:/etc/nginx -p 88:80 9bbf2937ac71
2fa62e43bff92da899a628df84073560935effe9a17eac7c4d041d514be3eda3


查看卷

[root@192 nginxhtml]# docker volume ls
DRIVER    VOLUME NAME
local     nginxconf

查看容器的详细信息

docker inspect 容器id

在这里插入图片描述

88端口访问

在这里插入图片描述

从容器外部修改nginx配置文件

在这里插入图片描述

进入容器内部查看并修改nginx.conf文件

在这里插入图片描述

root@2fa62e43bff9:/etc/nginx# echo '#update data' >> nginx.conf
root@2fa62e43bff9:/etc/nginx# cat nginx.conf
#测试,修改容器内部数据
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
#update data

再到容器外部查看数据是否同步

[root@192 _data]# cat nginx.conf
#测试,修改容器内部数据
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
#update data

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值