docker文件存放路径, 获取容器启动命令 *** 作

docker文件存放路径, 获取容器启动命令 *** 作,第1张

docker文件存放路径,获取容器启动命令 *** 作

本文主要介绍docker文件存储路径,并获取容器启动命令 *** 作,具有很好的参考价值。希望对大家有帮助。来和边肖一起看看吧。

容器已经创建。如何知道它的启动参数(在哪里挂载数据)?

#假设通过如下命令启动了一个容器 dockerrun-d--namemysql\ -p3306:3306\ -eMYSQL_ROOT_PASSWORD=123456\ --restart=always\ mysql:5.5--character-set-server=utf8 #如何通过容器名得知启动参数 [root@jenkins~]#dockerinspectmysql_cdh [ { "Id":"fbc3fba81b57bc5b5871746098b5f1f7ef0ed7716a786584a5effbb88ba156e6", "Created":"2019-09-25T01:43:37.720505875Z", "Path":"docker-entrypoint.sh", "Args":[ "--character-set-server=utf8" ], "HostConfig":{ "Binds":[ "mysql-data:/var/lib/mysql" ], "ContainerIDFile":"", "LogConfig":{ "Type":"json-file", "Config":{} }, "NetworkMode":"default", "PortBindings":{ "3306/tcp":[{"HostIp":"","HostPort":"3306"} ] }, "RestartPolicy":{ "Name":"always", "MaximumRetryCount":0 }, "Mounts":[ { "Type":"volume", "Name":"mysql-data", "Source":"/var/lib/docker/volumes/mysql-data/_data", "Destination":"/var/lib/mysql", "Driver":"local", "Mode":"z", "RW":true, "Propagation":"" } ],

1,镜像层:文件存储路径

[root@master~]#dockerimageinspectnginx|tail-n22 "GraphDriver":{ "Data":{ "LowerDir":"/var/lib/docker/overlay2/bf20cf788cc053f00ff1467525d50e19bd1cf07a2167f72511bdfcb28918a472/diff:/var/lib/docker/overlay2/317d80bb7ae58ed288be9ebd84aeb5b4b3a1c06f3211f5d1f32d89b629d1876e/diff", "MergedDir":"/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/merged", "UpperDir":"/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/diff", "WorkDir":"/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/work" }, "Name":"overlay2" },

2,容器层:文件存储路径

#1,启动容器 [root@master~]#dockerrun-d--namenginx2nginx a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8 #2,获取容器id [root@master~]#dockerinspectnginx2|grep-iid [root@master~]#dockerinspectnginx2|grep-iid "Id":"a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8", "Pid":2069, "ExecIDs":null, "ContainerIDFile":"", #查看容器临时文件--每次创建时随机生成的文件(容器层) [root@master~]#dockerinspectnginx2|grep-ipath "Path":"nginx", "ResolvConfPath":"/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/resolv.conf", "HostnamePath":"/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/hostname", "HostsPath":"/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/hosts", "LogPath":"/var/lib/docker/containers/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8/a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8-json.log", #通过容器id,查找容器数据存放目录:/var/lib/docker/overlay2/容器id ###### #对比上面的“镜像层:文件存放路径”,可以看到:容器通过LowerDir挂载的方式,映射了镜像层的文件 ###### [root@master~]#dockerinspectnginx2|grep-idir "LowerDir":"/var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b-init/diff:/var/lib/docker/overlay2/7782d0eb292fdc8bbd73bf9bae2d65468e8aba0bcd6baed55ac348618b80ae16/diff:/var/lib/docker/overlay2/bf20cf788cc053f00ff1467525d50e19bd1cf07a2167f72511bdfcb28918a472/diff:/var/lib/docker/overlay2/317d80bb7ae58ed288be9ebd84aeb5b4b3a1c06f3211f5d1f32d89b629d1876e/diff", "MergedDir":"/var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b/merged", "UpperDir":"/var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b/diff", "WorkDir":"/var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b/work"

后天修改集装箱港口

通过容器层文件,找到配置文件hostconfig.json,修改容器映射的端口。

[root@dockerd93185e3a0....2e544ccfa]#pwd /var/lib/docker/containers/d93185e3a0....2e544ccfa [root@dockerd93185e3a0....2e544ccfa]#cathostconfig.json {"Binds":["/dockersuperset:/home/superset"],"ContainerIDFile":"", "LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default", "PortBindings":{"8088/tcp":[{"HostIp":"","HostPort":"8099"}]}......

3、进入镜像容器文件存储目录并修改配置文件

#进入镜容器文件存储目录,修改配置文件 [root@master~]#cd/var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#ls difflinklowermergedwork [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#lsdiff/run/ nginx.pid [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#lsdiff/var/cache/nginx/ client_tempfastcgi_tempproxy_tempscgi_tempuwsgi_temp [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#lsmerged/ bin/dev/etc/lib/media/opt/root/sbin/sys/usr/ boot/.dockerenvhome/lib64/mnt/proc/run/srv/tmp/var/ [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#lsmerged/etc/nginx/ conf.dfastcgi_paramskoi-utfkoi-winmime.typesmodulesnginx.confscgi_paramsuwsgi_paramswin-utf [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#headmerged/etc/nginx/nginx.conf usernginx; worker_processes1; #在此处修改配置文件,把usernginx;worker_process1;这两行的分号去掉,看容器里面的配置是否更改 [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#headmerged/etc/nginx/nginx.conf-n3 usernginx worker_processes1 #登陆容器,查看修改的配置:验证是否生效 [root@masterd37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]#dockerexec-itnginx2bash root@a9c9f31cdccf:/#head/etc/nginx/nginx.conf-n3 usernginx worker_processes1

4、修改默认存储路径

a,重建/var/lib/docker目录 #备份数据到新的存放路径 servicedockerstop mkdir/docker.bak mv/var/lib/docker/*/docker.bak #创建软连接 mkdir/home/docker-data mv/docker.bak/*/home/docker-data/&&rmdir/docker.bak ln-s/home/docker-data/var/lib/docker b,修改配置 vi/usr/lib/systemd/system/docker.service ExecStart=/usr/bin/dockerd--graph/new-path/docker #reload配置文件 systemctldaemon-reload #重启docker systemctlrestartdocker.service

补充知识:Docker指定数据存储目录

Docker指定存储目录(原始参数图已过期。)

方法1

I.在Docker配置文件中配置/etc/Docker/daemon.json

当daemon.json文件没有内容时,将添加以下命令。如果有内容,你需要它。

cat<<EOF>>/etc/docker/daemon.json { "data-root":"/mnt/docker-data" } EOF systemctlrestartdocker

方法2

二、启动参数中的配置

vim/usr/lib/systemd/system/docker.service

在EXECStartinside后添加以下内容:

ExecStart=/usr/bin/dockerd--data-root='/home/docker' systemctldaemon-reload systemctlrestartdocker

以上docker文件存储路径和获取容器启动命令的 *** 作都是边肖分享的内容。希望给大家一个参考,支持我们。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/774124.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存