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
• 290 points
20 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 940 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
• 36,340 points
23 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
• 36,340 points
22 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,330 points
54 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,140 points
80 views
0 votes
1 answer

What is a docker file? How do I create a docker image with dockerfile?

 A Dockerfile is a script/text configuration file that contains ...READ MORE

answered Jun 7 in Docker by Sirajul
• 940 points
19 views
0 votes
1 answer

Can I run docker-compose inside a container?

Compose can also be run inside a ...READ MORE

answered Jun 10 in Docker by Sirajul
• 940 points
28 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.