Creating the Replica of the Container Environment

KUSHAGRA BANSAL
3 min readFeb 17, 2021

--

Prerequisite: Install docker on your AWS Linux ec2 instance

Command-1: Docker ps

It shows all running container at present

Command-2: Docker ps –a

It shows all running and closed container

Command-3: docker run –it — name TheKushagra ubuntu /bin/bash

It will create a container of image ubuntu with the name TheKushagra. Now you will enter in ubuntu terminal exit from it and check the docker container status using docker ps. No container will be shown because the container is terminated.

Command-4: Docker start TheKushagra

To start the container, use the above command and TheKushagra here is the name of the container. Now do docker ps and see the output. Also, using this command we can start any container.

Command-5: A. Docker stop TheKushagra

B. docker rm TheKushagra

Here, to delete a running container first stop the container and then use the ‘rm’ command.

Command-6: docker attach TheKushagra

Using this we can enter inside the running container.

Now,

We Have to create a Container from our own image. Therefore Create one container first.

1. Creating a Container

Command: docker run –it — name TheKushagra ubuntu /bin/bash

Here, we created and run a container of image ubuntu. See the above steps.

2. There are many default directories in a container.

Let’s take tmp directory

First, go inside a directory cd tmp/

Now, create a file inside the tmp directory.

Command: touch KushLogFile

Here, inside this file, we can store the logs of our work done inside this container. So that if we use this image in other machines we can verify that we have the same replica of the earlier container environment.

3. IF we want to see the difference between the base image and changes on it

Command: docker diff <Present_container_name>

o/p => C /root

A /root/.bash_history

C /tmp

A /tmp/ KushLogFile

D implies Delete, C implies Change, A implies Append or Addition.

4. Create an Image of this container

Command: docker commit <container_name> <update_image>

docker commit TheKushagra kush_new_image

Here, update_images means the name of the new image we will create.

5. Creating container from our updated image

Command: docker run –it –name TheKushagraNewContainer < update_image> /bin/bash

docker run –it –name TheKushagraNewContainer kush_new_image /bin/bash

6. Verify either new container is replicate or not

Use the below command to re-enter in a stopped container.

Command:

docker start TheKushagraNewContainer

docker attach TheKushagraNewContainer

--

--

No responses yet