How to make permanent changes to a Docker image immediately.

What happens if you need to adjust something inside a running container, such as installing a package or updating the configuration? Thats where the `docker commit` command comes in handy.

Docker images are immutable. Once built, they don't change. This ensures consistency, predictability, and stability. Every container created from the same image behaves exactly the same way, making version management secure and easy.

 

But what if you need to adjust something inside a running container, such as installing a package or updating the configuration? That's where the `docker commit` command comes in. It allows you to log changes in a running container and create a new image without touching the original image. This is great for testing fixes, iterating quickly, and deploying custom images without rebuilding from scratch.

 

Why isn't the Docker image changing?

A Docker image consists of multiple read-only layers. When you run a container, Docker adds a thin write layer on top called the container layer. Any changes you make only occur within this top layer. After the container is removed, all changes within that layer are lost, leaving the original image intact.

  • This design offers several benefits:
  • All containers from the same image behave the same way, ensuring consistency.
  • Changes in one non-image container affect other containers, providing predictability.

You can safely tag specific image versions without risk. This design offers excellent stability, but it limits you when you want to make quick changes to a running container. That's where the `docker commit` command comes in.

Create a new image from a running container.

When you run the `docker commit` command, Docker records the current state of a running container and creates a new image from it. It captures the container's file system, saving any changes you've made, such as installed packages, updated configurations, or modified files, as a new image layer. This way, the original image remains unaffected, allowing for quick experimentation and iteration.

 

Images 1 of How to make permanent changes to a Docker image immediately.

This makes it ideal for saving custom base settings for future reuse, applying minor bug fixes or configuration changes during testing, or sharing the updated image with your team without having to rebuild the Dockerfile from scratch.

You can use the `docker commit` command with the following syntax to create a new image from a running container:

 

docker commit [OPTIONS] CONTAINER_ID NEW_IMAGE_NAME[:TAG]

Here, `CONTAINER_ID` is the ID or name of the container you want to capture, `NEW_IMAGE_NAME` is the name you want to give the new image, and `TAG` is optional, defaulting to `latest`.

Note : `docker commit` is an old alias for `docker container commit`; they are the same thing.

The `docker commit` command provides several options that allow you to add metadata, apply configuration changes, and control how the commit process works. The table below summarizes all supported options:

 

See how the `docker commit` command works.

Suppose you want to install curl in an Alpine container without rebuilding the Dockerfile. To do this, run a container from the original image:

docker run -it alpine:latest /bin/sh

After entering the container, make the necessary changes:

apk update && apk add curl

Images 2 of How to make permanent changes to a Docker image immediately.

Now let's exit the container:

exit

Next, commit the container as a new image:

docker commit alpine-with-curl:1.0

Images 3 of How to make permanent changes to a Docker image immediately.

Verify your new image:

docker images

Now you have a new image ready to run anywhere, with curl pre-installed.

Images 4 of How to make permanent changes to a Docker image immediately.

Run the new image to check the saved changes.

After creating the new image, you can run a container from it to verify that the changes have been saved.

docker run -it alpine-with-curl:1.0 /bin/sh

This command opens an interactive shell inside the container based on the image `alpine-with-curl:1.0`. Once inside, you can check if your changes are still intact.

curl --version

This command demonstrates that the changes have been preserved in the new image.

Images 5 of How to make permanent changes to a Docker image immediately.

Close
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup