Is it possible to create a custom docker image from a running docker container?

0 votes
I want to create a ubuntu image with some feature previously configured in it. How do I go about creating this custom ubuntu image using a running ubuntu container?
Jun 7 in Docker by Sam
• 850 points
34 views

1 answer to this question.

0 votes

Yes you can create a custom docker image using a running container.

There are two ways of creating a custom docker image:

  1. Using a Running Docker container.
  2. Using a Dockerfile.

To create an image from a running docker container :

  • First start the container in attached mode: 
docker run -it --name forcommitcontainer ubuntu
  • Where "forcommitcontainer" is the name of the container created from "ubuntu" image.
  • Once the container is started in the attached mode, you can configure whatever you want, make the necessary installations and configurations.
  • Say you want an ubuntu image with Vim installed, we would be making the necessary installations and saving the state of the container. In order to install Vim in the container,
apt-get install vim
  • Now you just need to save the state of the container. Everytime you install this custom ubuntu image, vim package will be installed automatically.
  • Come out of the container:
Ctrl+p Ctrl+q
  • And to save the state of the container 
docker commit forcommitcontainer devopstrainer/ubuntu:vim
  • "forcommitcontainer" -> name of the container, "devopstrainer" -> username , "ubuntu" -> repository name along with a tag "vim", so that by seeing itself you understand that its an ubuntu image with vim package installed.
  • I can push it to my repositories on dockerhub later on if required.
docker images
  • A new image is created (devopstrainer/ubuntu) which can be pushed to the dockerhub. Now run this
docker run -it devopstrainer/ubuntu:vim 
  • When you check you will find that vim will be automatically installed on the new container that is created using the custom ubuntu image.

  • You can check the status of the container :
 docker history devopstrainer/ubuntu:vim

This will show the date when the container is created, image, created by, size etc.

answered Jun 7 by Sirajul
• 4,360 points

Related Questions In Docker

0 votes
1 answer
0 votes
1 answer

Is it possible to start a shell session in a running container (without ssh)

use this docker exec -it "id of running ...READ MORE

answered Jul 25, 2018 in Docker by Kalgi
• 37,320 points
33 views
0 votes
1 answer

Is it possible to start a shell session in a running container (without ssh)

use this docker exec -it "id of running ...READ MORE

answered Jul 27, 2018 in Docker by Kalgi
• 37,320 points
32 views
0 votes
1 answer

How to continue running a docker container which is already exited?

Restart an existing container after you exited ...READ MORE

answered Jul 19, 2018 in Docker by Sophie may
• 9,370 points
70 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,160 points
95 views
0 votes
1 answer

Is it possible to spin-up a docker host on a cloud platform?

Yes, It is definitely possible to spin ...READ MORE

answered Jul 4 in Docker by Sirajul
• 4,360 points
33 views