Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to duplicate running docker container

I have a docker container running

> docker container ls
                                                                                                                         
CONTAINER ID  IMAGE   COMMAND  CREATED         STATUS         PORTS  NAMES
c5a24953e383  gradle  "bash"   22 minutes ago  Up 22 minutes  #      naughty_torvalds

Can I duplicate this running container and run it? What is the command for it?

like image 770
Mahabub Avatar asked Mar 09 '18 11:03

Mahabub


People also ask

How do I clone a running Docker container?

To 'clone' a container, you'll have to make an image of that container first, you can do so by "committing" the container. Docker will (by default) pause all processes running in the container during commit to preserve data-consistency. Commit my_container as an image called my_container_snapshot , and tag it yymmdd .

Can I copy Docker container?

Description. The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container.


2 Answers

You can create a new image from that container using the docker commit command:

docker commit c5a24953e383 newimagename

And then start a new container from that image:

docker run [...same arguments as the other one...] newimagename
like image 175
larsks Avatar answered Sep 16 '22 13:09

larsks


You can use:

docker run --name duplicateImage --volumes-from Image -d -p 3000:80 nginix:latest

The --volumes-from Image duplicates the 'Image' container.

So you will now have a container named Image and a container named duplicateImage and they will contain the same image that is running (a container).

like image 44
AlwaysLearning Avatar answered Sep 18 '22 13:09

AlwaysLearning