Method 1: Modify the configuration file (need to stop the docker service) 1. Stop the docker service systemctl stop docker.service (critical, the docker service must be stopped before modification) 2. vim /var/lib/docker/containers/container-ID/config.v2.json Modify the directory location in the configuration file, then save and exit
3. Start the docker service
4. Start the Docker container
Method 2: Submit an existing container as a new image and then rerun it $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5a3422adeead ubuntu:14.04 "/bin/bash" About a minute ago Exited (0) About a minute ago agitated_newton $ docker commit 5a3422adeead newimagename $ docker run -ti -v "$PWD/dir1":/dir1 -v "$PWD/dir2":/dir2 newimagename /bin/bash Then stop the old container, and use this new one. If for some reason you need the new container to use the old name, use docker rename after removing the old container. Method 3: Export the container as an image, then import it as a new image $docker container export -o ./myimage.docker container ID $docker import ./myimage.docker newimagename $docker run -ti -v "$PWD/dir1":/dir1 -v "$PWD/dir2":/dir2 newimagename /bin/bash Then stop the old container, and use this new one. If for some reason you need the new container to use the old name, use docker rename after removing the old container. Additional knowledge: How to prevent data loss after Docker restarts, teach you how to mount data volumes When you use Docker to deploy web applications or MySQL databases, you will find that when the container is restarted, the logs or database data generated during the container operation will be cleared. So how do we save this data? This requires understanding how Docker mounts the host disk directory to permanently store data. 1. Execute Docker Volume when creating a container Use the docker run command to run a Docker container, use the image ubuntu/nginx, and mount the local directory /tmp/source to the container directory /tmp/destination
A Docker container is created based on the ubuntu/nginx image. The name of the specified container is test, which is specified by the --name option. The Docker Volume is specified by the --volume (can be abbreviated as -v) option, and the host's /tmp/source directory corresponds one-to-one with the /tmp/destination directory in the container. 2. View Docker Volume Use the docker inspect command to view detailed information about the Docker container:
Using the --format option, you can selectively view the required container information. .Mount is the Docker Volume information of the container. python -m json.tool can format the output json string for display. Source represents the directory on the host, that is, /tmp/source. Destination is the directory in the container, that is, /tmp/destination. 3. Local files can be synchronized to the container Create a new hello.txt file in the local /tmp/source directory
The hello.txt file is visible in the container /tmp/destination/ directory Using the docker exec command, you can execute commands in a container.
Therefore, modifications to the directory /tmp/source/ on the host can be synchronized to the container directory /tmp/destination/. 4. Container files can be synchronized to the host machine Create a new world.txt file in the container /tmp/destination directory
The world.txt file is visible in the host machine's /tmp/source/ directory
The above summary of 3 methods of docker-modifying container mount directories 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:
|
<<: Causes and solutions for cross-domain issues in Ajax requests
>>: A brief discussion on the comparison of varchar, char and text in postgresql database
Problem explanation: When using the CSS animation...
I recently wanted to convert a website to https a...
question Recently I needed to log in to a private...
1. What is positioning? The position attribute in...
This article uses examples to illustrate the prin...
Carousel animation can improve the appearance and...
Nowadays, whether you are on the sofa at home or ...
A common suggestion is to create indexes for WHER...
In writing styles, we can often see this situatio...
This article example shares the specific code of ...
In a word: if you buy a cloud server from any maj...
1. Same IP address, different port numbers Virtua...
This article mainly introduces the wonderful use ...
I won’t waste any more time talking nonsense, let...
Table of contents Preface call usage accomplish A...