主頁 > 知識(shí)庫 > docker文件存放路徑, 獲取容器啟動(dòng)命令操作

docker文件存放路徑, 獲取容器啟動(dòng)命令操作

熱門標(biāo)簽:智能電銷機(jī)器人真的有用么 電銷智能機(jī)器人試用 百度地圖底圖標(biāo)注 激光標(biāo)記地圖標(biāo)注 新鄉(xiāng)牧野400電話申請 企業(yè)辦理400電話收費(fèi)標(biāo)準(zhǔn) 中國地圖標(biāo)注上各個(gè)省 高德地圖標(biāo)注足跡怎么打標(biāo) 撫州市城區(qū)地圖標(biāo)注

容器早已創(chuàng)建好,如何得知它的啟動(dòng)參數(shù)(數(shù)據(jù)掛載到哪)

#假設(shè)通過如下命令啟動(dòng)了一個(gè)容器
docker run -d --name mysql\

-p 3306:3306\

-e MYSQL_ROOT_PASSWORD=123456\

--restart=always\

mysql:5.5 --character-set-server=utf8

#如何通過容器名得知啟動(dòng)參數(shù)
[root@jenkins ~]# docker inspect mysql_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 ~]# docker image inspect nginx |tail -n 22
    "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, 啟動(dòng)容器
[root@master ~]# docker run -d --name nginx2 nginx
a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8

#2, 獲取容器id
[root@master ~]# docker inspect nginx2 | grep -i id 
[root@master ~]# docker inspect nginx2 | grep -i id 
    "Id": "a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8",
      "Pid": 2069,
    "ExecIDs": null,
      "ContainerIDFile": "",
  
#查看容器臨時(shí)文件--每次創(chuàng)建時(shí)隨機(jī)生成的文件(容器層)
[root@master ~]# docker inspect nginx2 | grep -i path
    "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, 查找容器數(shù)據(jù)存放目錄: /var/lib/docker/overlay2/容器id
######
#對比上面的“鏡像層:文件存放路徑”,可以看到 :容器通過LowerDir 掛載的方式,映射了鏡像層的文件
######
[root@master ~]# docker inspect nginx2 | grep -i dir
        "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@docker d93185e3a0....2e544ccfa]# pwd
/var/lib/docker/containers/d93185e3a0....2e544ccfa
[root@docker d93185e3a0....2e544ccfa]# cat hostconfig.json 
{"Binds":["/dockersuperset:/home/superset"],"ContainerIDFile":"",
"LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default",
"PortBindings":{"8088/tcp":[{"HostIp":"","HostPort":"8099"}]}......

3, 進(jìn)入鏡容器文件存儲(chǔ)目錄, 修改配置文件

# 進(jìn)入鏡容器文件存儲(chǔ)目錄, 修改配置文件
[root@master ~]# cd /var/lib/docker/overlay2/d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b
[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# ls
diff link lower merged work

[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# ls diff/run/
nginx.pid
[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# ls diff/var/cache/nginx/
client_temp fastcgi_temp proxy_temp scgi_temp uwsgi_temp

[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# ls merged/
bin/    dev/    etc/    lib/    media/   opt/    root/    sbin/    sys/    usr/    
boot/    .dockerenv home/    lib64/   mnt/    proc/    run/    srv/    tmp/    var/    

[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# ls merged/etc/nginx/
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf

[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# head merged/etc/nginx/nginx.conf 
user nginx;
worker_processes 1;

#在此處修改配置文件,把user nginx; worker_process 1; 這兩行的分號(hào)去掉,看容器里面的配置是否更改
[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# head merged/etc/nginx/nginx.conf -n 3
user nginx
worker_processes 1

#登陸容器,查看修改的配置: 驗(yàn)證是否生效
[root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# docker exec -it nginx2 bash
root@a9c9f31cdccf:/# head /etc/nginx/nginx.conf -n 3
user nginx
worker_processes 1

4, 修改默認(rèn)存儲(chǔ)路徑

a, 重建/var/lib/docker目錄
#備份數(shù)據(jù)到新的存放路徑
service docker stop
mkdir /docker.bak
mv /var/lib/docker/* /docker.bak

#創(chuàng)建軟連接
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配置文件 
systemctl daemon-reload 
#重啟docker 
systemctl restart docker.service

補(bǔ)充知識(shí):Docker 指定數(shù)據(jù)儲(chǔ)存目錄

Docker 指定儲(chǔ)存目錄(原參數(shù) --graph 已經(jīng)失效 。)

方法一

一、在 Docker 配置文件中配置 /etc/docker/daemon.json

下面的命令是在 daemon.json 文件沒有內(nèi)容的時(shí)候進(jìn)行添加的。如果有內(nèi)容,就需要

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

方法二

二、在啟動(dòng)參數(shù)中配置

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

在里面的EXECStart的后面增加后如下:

ExecStart=/usr/bin/dockerd --data-root='/home/docker'
systemctl daemon-reload
systemctl restart docker

以上這篇docker文件存放路徑, 獲取容器啟動(dòng)命令操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

標(biāo)簽:臨汾 辛集 西安 海西 南通 邯鄲 延安 忻州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《docker文件存放路徑, 獲取容器啟動(dòng)命令操作》,本文關(guān)鍵詞  docker,文件,存放,路徑,獲取,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《docker文件存放路徑, 獲取容器啟動(dòng)命令操作》相關(guān)的同類信息!
  • 本頁收集關(guān)于docker文件存放路徑, 獲取容器啟動(dòng)命令操作的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章