Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicating docker container for debugging

Tags:

docker

I have a running docker container. I have done some useful works in the running docker container. I have done these works not part of dockerfile, i have done it inside the container.[Eg: I have installed ping inside the container, not from docker file]

Now, i got stuck at a place. I am not sure if i debug in the same container, i may loose the thing that i have done so far inside that container.

So i would like to create a duplicate copy of it with all the things available in that running container[like i don't want to build a container from image and repeat all the suucessful steps achieved in the running container and then start my debuggging. I don't want to re-install ping in my second container].

Totally, How can i duplicate a container? If not what are all the possibilities?

like image 451
Gibbs Avatar asked Feb 12 '15 06:02

Gibbs


People also ask

Can you clone a 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 .

How do I keep my docker container running for debugging?

Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.

How do I copy a docker container?

To summarize, follow these steps to copy a file from a Docker container to a host machine: Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container.

Can two docker containers share the same volume?

Multiple containers can run with the same volume when they need access to shared data. Docker creates a local volume by default.


1 Answers

  1. Create a base image and run it

    docker run -it <base_image> /bin/bash 
  2. Make necessary changes

    yum install ping 
  3. Commit it with a new name

    docker commit <hash tag of running container> new_image 

Now if you open new_image by running

docker run -it new_image /bin/bash 

You can see ping is installed in it.

Open base_image and there is no ping installed in it.

Hope it answered your question.

like image 150
Pratik Avatar answered Sep 28 '22 01:09

Pratik