Docker file storage path, get container startup command operation

Docker file storage path, get container startup command operation

The container has already been created, how to know its startup parameters (where the data is mounted)

#Suppose a container is started by the following command docker run -d --name mysql\
-p 3306:3306\
-e MYSQL_ROOT_PASSWORD=123456\
--restart=always\
mysql:5.5 --character-set-server=utf8

#How to get the startup parameters through the container name [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. Image layer: file storage path

[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. Container layer: file storage path

#1, Start the container [root@master ~]# docker run -d --name nginx2 nginx
a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8

#2, Get the container id
[root@master ~]# docker inspect nginx2 | grep -i id 
[root@master ~]# docker inspect nginx2 | grep -i id 
    "Id": "a9c9f31cdccf13c3385f3de33443325d2e14d69458e6d679e54c8cf9e5ff24c8",
      "Pid": 2069,
    "ExecIDs": null,
      "ContainerIDFile": "",
  
#View container temporary files--randomly generated files each time they are created (container layer)
[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",
 
#Use container id to find the directory where container data is stored: /var/lib/docker/overlay2/containerid
######
#Compared with the above "Image layer: file storage path", you can see that the container maps the image layer files through the LowerDir mounting method######
[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"

Modify the container port the day after tomorrow

Find the configuration file hostconfig.json through the container layer file and modify the port mapped by the container

[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. Enter the mirror container file storage directory and modify the configuration file

# Enter the mirror container file storage directory and modify the configuration file [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;

#Modify the configuration file here, remove the semicolons of the two lines user nginx; worker_process 1; to see if the configuration in the container has changed [root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# head merged/etc/nginx/nginx.conf -n 3
user nginx
worker_processes 1

#Log in to the container and view the modified configuration: Verify whether it is effective [root@master d37ff828e63081be6fcfefc73891e7b455596cb921c8021fbf9571f330c0599b]# docker exec -it nginx2 bash
root@a9c9f31cdccf:/# head /etc/nginx/nginx.conf -n 3
user nginx
worker_processes 1

4. Modify the default storage path

a, Rebuild the /var/lib/docker directory #Backup data to the new storage path service docker stop
mkdir /docker.bak
mv /var/lib/docker/* /docker.bak

#Create a soft link mkdir /home/docker-data
mv /docker.bak/* /home/docker-data/ && rmdir /docker.bak
ln -s /home/docker-data /var/lib/docker
b. Modify the configuration vi /usr/lib/systemd/system/docker.service 
ExecStart=/usr/bin/dockerd --graph /new-path/docker 

#reload configuration file systemctl daemon-reload 
#Restart Docker 
systemctl restart docker.service

Additional knowledge: Docker specifies the data storage directory

Docker specifies the storage directory (the original parameter --graph is invalid.)

Method 1

1. Configure /etc/docker/daemon.json in the Docker configuration file

The following command is added when the daemon.json file has no content. If there is content, you need

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

Method 2

2. Configure in startup parameters

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

Add the following after EXECStart:

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

The above article about docker file storage path and getting container startup command operation is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Each time Docker starts a container, the IP and hosts specified operations
  • Detailed explanation of Shell script control docker container startup order
  • Docker modifies the configuration information of an unstarted container
  • Dockerfile implementation code when starting two processes in a docker container
  • Solve the problem of docker container exiting immediately after starting
  • Docker batch start and close all containers

<<:  Solutions to the Problem of Creating XHTML and CSS Web Pages

>>:  Analysis of Mysql transaction characteristics and level principles

Recommend

Example code for implementing photo stacking effect with CSS

Achieve results step 1. Initial index.html To bui...

Refs and Ref Details in Vue3

The editor also shares with you the corresponding...

Detailed installation and use of docker-compose

Docker Compose is a Docker tool for defining and ...

Docker swarm simple tutorial

swarm three virtual machines 132,133,134 1. Initi...

iframe multi-layer nesting, unlimited nesting, highly adaptive solution

There are three pages A, B, and C. Page A contains...

How to deploy Vue project using Docker image + nginx

1. Packaging Vue project Enter the following name...

Detailed explanation of MYSQL log and backup and restore issues

This article shares MYSQL logs and backup and res...

How to create a stored procedure in MySQL and add records in a loop

This article uses an example to describe how to c...

Native JS to implement the aircraft war game

This article example shares the specific code of ...

Detailed explanation of MySQL cumulative calculation implementation method

Table of contents Preface Demand Analysis Mysql u...

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...

Solution to JS out-of-precision number problem

The most understandable explanation of the accura...

The pitfalls and solutions caused by the default value of sql_mode in MySQL 5.7

During normal project development, if the MySQL v...