Mahabub
Mahabub

Reputation: 531

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?

Upvotes: 25

Views: 42431

Answers (2)

AlwaysLearning
AlwaysLearning

Reputation: 25

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).

Upvotes: 0

larsks
larsks

Reputation: 311288

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

Upvotes: 51

Related Questions