VOOZH about

URL: https://thenewstack.io/container-basics-how-to-commit-changes-to-a-docker-image/

⇱ Container Basics: How to Commit Changes to a Docker Image - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2019-06-04 12:00:48
Container Basics: How to Commit Changes to a Docker Image
tutorial,
Containers

Container Basics: How to Commit Changes to a Docker Image

This tutorial will show you how to build an image, commit the changes to the image, and how to deploy containers.
Jun 4th, 2019 12:00pm by Jack Wallen
👁 Featued image for: Container Basics: How to Commit Changes to a Docker Image
Feature Image by StartupStockPhotos from Pixabay.

Docker is a tool that can help make your company more agile and flexible. With containers, you can quickly roll out services based on pre-built or custom images. Even with this level of flexibility, there are many ways you can make Docker containers even more efficient. One such method is creating template images that will be used as the base for your containers. Say, for example, you need to be able to deploy containers all based on an image that contains a specific set of tools (for example an NGINX image with MySQL, PHP, build-essentials, and nano). Instead of having to build that same image every time you roll out a container, why not create a single image, with those exact tools, that can be used as a template for all of your containers?

Believe it or not, the creation of such a template isn’t all that hard. To do so, you build your image, commit the changes to the image, and you’re ready to start deploying containers.

Using this method makes for a much more efficient process, one that will go a long way to boost your container productivity.

Let’s make this happen.

I’ll be demonstrating the process using the official NGINX image and will be customizing the image from Docker Hub. I will assume you already have Docker up and running on your platform of choice and are ready to go.

Pulling the Official Image

The first step in the process is pulling down the official image from Docker Hub. To pull this image, issue the command:

docker pull nginx

The image should pull down fairly quickly (Figure A).

👁 Image

Figure A: Pulling down the official NGINX image from Docker Hub.

With the image downloaded, we can now deploy the container so that it can be customized to meet our specific needs.

Deploying the Container

What we have to do is deploy our new container in such a way that we have access to the associated bash prompt (so we can work within the container). To do that, we deploy with the command:

docker run --name nginx-template -p 8080:80 -e TERM=xterm -d nginx

The above command break down look like this:

  • docker run instructs Docker that we are running a new container.
  • –name nginx-template instructs Docker to name the new container nginx-template
  • -p 8080:80 instructs Docker to expose the internal container port 80 to the network port 8080.
  • -e TERM=xterm defines our terminal variable.
  • -d launches the container in the background.
  • nginx is the name of the image to be used for the container.

Accessing and Modifying the Container

Our next step is to gain access to the container. When you issue the above command, Docker will report back the ID of the contain (Figure B). This ID is what you use to access the container.

👁 Image

Figure B: Our newly deployed container ID.

What we need to use is the first four digits of the container ID. So in our example, we’d use b1d5.

docker exec -it b1d5 bash

NOTE: When you run the command, you will be given a completely different ID.

At this point, you will find yourself at the bash prompt for the NGINX container (Figure C).

👁 Image

Figure C: The bash prompt for our newly-deployed container.

Installing Our Tools

The next step is installing the necessary tools. Remember, we’re going to install build-essential, PHP, MySQL, and nano. Before you attempt to install anything, you’ll first need to update apt with the command:

apt-get update

Once that command completes, install the necessary software with the following commands:

apt-get install nano
​apt-get install build-essential
​apt-get install php php-mysql
apt-get install mysql-server

When you’ve completed the above commands exit from the NGINX bash prompt with the exit command.

Committing Your Changes

Time to commit your changes to create a new image based on our additions. To do this, we need to once again use the container ID (in our example the first four characters, b1d5). When we commit these changes we effectively create a new image that will include all of the additions that were made to the original image. The command to do this is:

docker commit b1d5 nginx-template

This command will complete in less than 30 seconds. When it finishes, issue the command docker images to see that you now have a newly created NGINX image that contains MySQL, PHP, build-essential, and nano (Figure D).

👁 Image

Figure D: Our newly created image is listed.

Congratulations, you now have a customized image for which to base your containers. You could deploy a new container with this image using a command:

docker run --name nginx-dev -p 8080:80 -e TERM=xterm -d nginx-template

Once the container is deployed, access it’s bash prompt (in the same manner you did earlier) and you will see all of the additional software is there, ready to be used.

Simple Container Templates

This is just one route to making container deployment easier. If you tend to roll out containers, and find yourself having to constantly add the same base software to the image, you might want to consider using this approach, to make the process significantly more efficient.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.