Docker-three ways to modify the mounting directory of the container

Original: docker-Three ways to modify the mounting directory of the container

Method 1: Modify the configuration file (need to stop the docker service)
1. Stop the docker service
systemctl stop docker.service (key, you must stop the docker service 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

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

  
  
 
 
  • 1

3. Start the docker service
systemctl start docker.service
4. Start the docker container
docker start <container-name / ID>
Method 2: Submit the existing container as a new image, and then re-run 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

  
  
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

Then stop the old container and use this new container. If for some reason the new container needs to use the old name, please use docker rename after deleting the old container.
Method 3: export the container as a mirror, and then import 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

  
  
 
 
  • 1
  • 2
  • 3

Then stop the old container and use this new container. If for some reason the new container needs to use the old name, please use docker rename after deleting the old container.

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12690383.html