Docker container: Build images from a container


Like we can create an image from a Dockerfile, we can create a container from an image too.

The steps to do that is as follows:

Deploy a container from an image:

[root@gw20-lap-doc1 sandbox]# docker run -it centos /bin/bash

Now create a new folder in the container:

[root@4bab5b1c66ed /]# mkdir /My_New_Folder

Check if the folder got created by running a ls command.

[root@4bab5b1c66ed /]# yum install redis -y

This will install  httpd service.

Now open another terminal window connecting to your host where the docker is running and run the following command:

[root@gw20-lap-doc1 ~]# docker ps -all

Identify the container ID of the container running in the other terminal window. In my system the one I can find is 4bab5b1c66ed

Now run the following command:

[root@gw20-lap-doc1 ~]# docker commit 4bab5b1c66ed shiju_centos_2

Just create an image

[root@gw20-lap-doc1 ~]# docker commit -c ‘CMD [“redis-server”]’ 4bab5b1c66ed shiju_centos_3

Create an image an execute the command to start redis server in the container that will be deployed using the image.