Create a Docker Image from Container.

Maheshwar Ligade
techwasti
Published in
2 min readNov 19, 2020

--

In this article, we will see how to use the “ docker commit “ command to create an image from the container.

Most of us are familiar with docker and container platforms and all most everyone used “ docker run ” command to create a container from the image but do you know how to create a docker image from running docker container.

Why we have to create an image from a container?

While creating the containers in a certain situation we did some config changes or file changes in the container and after validation, we want to make sure those should be available in an image but the reverse way not feasible, if we remove the container then these changes will get vanish, so instead of we do manually changes in docker file and then create a container from it we can use docker commit command.

Create a new image from a container’s changes.

Syntax:

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

It is better to use Dockerfiles to manage your images in a documented and maintainable way.

You are running an Ubuntu container on your local machine,

$ docker run ubuntu:12.04$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3f279d17e0a ubuntu:12.04 /bin/bash

--

--

Maheshwar Ligade
techwasti

Learner, Full Stack Developer, blogger, amateur #ML,#DL,#AI dev in the quantum moment. I run https://techwasti.com/ to post all my articles.