Docker

Docker Update Image Example

Welcome readers, in this tutorial, we will see how to update a docker image.

1. Introduction to Docker

In the present world, Docker is an important term,

  • Often used in CI/CD platform that packages and runs the application with its dependencies inside a container
  • Is a standard for Linux Containers
  • A Container is a runtime that runs under any Linux kernel and provides a private machine-like space under Linux

1.1 Docker Terminology

  • Image: Representation of Docker container i.e. a JAR or WAR file in Java
  • Container: Runtime of Docker i.e. a deployed and running Docker image. For example, an executable Spring Boot jar
  • Engine: The code that manages, creates and runs the Docker containers
  • Hub: A public developers registry to distribute their code
  • Repository: A collection of Docker related images i.e. different versions of the same application

1.2 Docker Command Basics

Here’s an example command.

Docker Update Image - Basic structure
Fig. 1: Basic structure

1.3 Need for using Docker

  • For environment replication, while the code runs locally on the machine
  • For numerous deployment phases i.e. Dev/Test/QA
  • For version control and distributing the application’s OS within a team

1.4 Setting up Docker

If someone needs to go through the Docker installation, please watch this video.

To start with this tutorial, we are hoping that users at present have the Docker installed on a Windows operating system.

2. Docker Update Image Example

Open the command line and follow the below steps to update a docker image.

2.1 Pull a Docker image and adding ‘temp’ directory

The first step is to pull the latest centos image from the Docker Hub.

docker pull

Once the image is successfully downloaded doing docker images will list down the downloaded images.

Docker Update Image - List of Docker images
Fig. 2: List of Docker images

Now we will run the Docker container in a bash interactive mode.

docker run -it --name="centos_test" centos /bin/bash

Once we are inside the container, we will create a new directory and add the first file to that directory.

# mkdir temp

# cd temp

# echo "Hello World" > first_file

# cat first_file

# ls -ltr

The next step is to build the new image with the Docker commit command using the newly created docker container. Please remember to run this command from the Docker host and not from the Docker container.

docker commit -m="This is a test image for jcg assignment" centos_test centos_jcg_assignment

Where,

  • -m="<some_commit_message>": Commit message
  • centos_test: Refers to the container name from which you’re creating the image
  • centos_jcg_assignment: Name of the newly created image

Once done, the new image will be displayed in the list of docker images.

Docker Update Image - Updated list of Docker images
Fig. 3: Updated list of Docker images

2.2 Testing the new Docker image

To test the newly created Docker image we’ll run it in the bash interactive mode.

1
docker run -it --name="image_testing" centos_jcg_assignment /bin/bash

Check for the sample directory and the welcome file created earlier in the image. Try out these commands in your development environment to practice and learn.

3. Conclusion

That is all for this tutorial and I hope the tutorial will help you understand the basic commands to update a Docker image. Happy Learning and do not forget to share!

4. Download the source code

Download
You can download the full source code of this example here: Docker Update Image Example

Yatin

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button