About "There directory mount / no directory is mounted" containers stored as image

No container directory is mounted

1, i.e. the host is not performed with the container path mapping, so we can use the direct commands: docker commit 容器名称/容器ID 镜像名:标签号, a mirror image of the storage container; (wherein image name and tag number are we randomly taken, and our new image name tag number!)

2, we can not determine the presence of the host vessel and the directory is mounted / path mapping before, we can use the command: docker inspect --format='{{.Mounts}}' 容器名(wherein, the container named container name we want to test)

Container directory is mounted

1, first of all, we have the presence of the container when the container is mounted directory is saved as a new image, which will be discarded all the data will not be saved in the new image, so that we can not directly use the save command as above is a mirror image;

2, the solution: We can put the container A with a directory mount / path mapped after a respective host files are copied to another directory backup folder, and then a new image storage container A, with the new mirror to create a container B and directory mount / path mapping , the mapped path to the backup file folder on the host, so since we use the container B will be able to create a new image data in the original host of the original path!

3, instructions are as follows: cp -rf /usr/local/project/ /usr/local/baseproject(wherein the / usr / local / project original directory, / usr / local / baseproject backup directory);
and A is a mirror holding vessel: docker commit 新镜像名:标签号creating a new image using the container B and the backup directory mapping:docker run -id --name=容器B -p 8081:8080 -v /usr/local/baseproject:/usr/local/tomcat/webapps --privileged=true 新镜像名:标签号

docker common commands summary:

-id: create and run a daemon container;
Expediting IT: Create the container into the container and start the command line;
-v: catalog for the host to mount the container directory / path mapping;
-p: host port and container port mapping ;
-name: container name;
LS: View a list of files in the current directory;
cd /: go to the root directory;
CAT: open / view the file;
echo the Hello, world> hello.html: files created hello.html and enter the "helloworld" to it;
Docker Exec: into the container, and open the command line terminal
rm: delete
mkdir: create a folder for
docker ps: container View running
docker ps -a: View all containers
docker run - it: create interactive container and enter the command line
docker run -id: create a guardian container (exit does not turn off the background) and enter the command line
ctrl + p + q: quit does not stop the current container
systemctl daemon-reload: reload the configuration file (usually after configuring the domestic accelerator)
systemctl restart Docker: restart Docker
-privileged = to true in a privileged way to start the container

Published 31 original articles · won praise 12 · views 3735

Guess you like

Origin blog.csdn.net/z19950712/article/details/104202628