Ashwani Kumar
Ashwani Kumar

Reputation: 19

How can I map a volume in a running docker container?

I am running jenkins docker container. how can keep jenkins backup folder in my current OS ?

Upvotes: 1

Views: 610

Answers (2)

YellowStrawHatter
YellowStrawHatter

Reputation: 948

First of all, you need to create a new image from the running container :

$ docker ps  -a
CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS                          PORTS               NAMES
c3f279d17e0a        jenkins:latest        "/bin/bash"              7 days ago   Up 25 hours                       jenkins


$ docker commit jenkins newjenkinsimage:v2

This image takes the exact same state as the running container, check the result with the following command :

$ docker images
REPOSITORY                        TAG                 ID                  CREATED             SIZE
newjenkinsimage                   v2                  f5283438590d        16 seconds ago      335.7 MB

Finally you need to run a new container from the new image and mount a volume :

$ docker run -it --name newjenkins -v /path/to/backup/file:/backup newjenkinsimage:v2 

PS : for the -v argument, The format is host-src:container-dest

Upvotes: 0

kstromeiraos
kstromeiraos

Reputation: 5037

You need to use -v flag in docker run this way:

docker run -v /Users/<path>:/<container path>

This will map your /Users/ directory to the container directory specified.

You can find more information here: https://docs.docker.com/engine/tutorials/dockervolumes/

Upvotes: 1

Related Questions