Home  >  Article  >  Operation and Maintenance  >  How to remount a directory that is already running docker

How to remount a directory that is already running docker

尚
Original
2020-03-30 11:08:0916274browse

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image, and then publish it to any popular Linux or Windows machine, which can also be virtualized.

How to remount a directory that is already running docker

How to remount the directory with already running docker:

1. First stop the running docker container, and then remount the directory by modifying the configuration file

1. Stop the docker service

systemctl stop docker.service(关键,修改之前必须停止docker服务)

2. Use the vim /var/lib/docker/containers/container-ID/config.v2.json command to open the configuration file and modify the configuration file. Directory location, then save and exit

 "MountPoints":{"/home":{"Source":"/docker","Destination":"/home","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"//docker/","Target":"/home"}}}

3. Start the docker service

systemctl start docker.service

4. Start the docker container

docker start <container-name/ID>

2. Submit the existing container as a new image, and then run it again 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 stops the old container and uses this new container, if for some reason you need the new container to use the old name, use docker rename after deleting the old container.

3. Export the container as a mirror, and then import it as a new mirror

$docker container export -o ./myimage.docker 容器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 container. If for some reason you need the new container to use the old name, please Use docker rename after deleting the old container.

For more related tutorials, please pay attention to the docker tutorial column on the PHP Chinese website.

The above is the detailed content of How to remount a directory that is already running docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn