Docker provides a simple way to configure any docker image and create your own custom image with the help of the dockerfile.
Ubuntu is a Debian-based Linux operating system based on free software. Keycloak is an open source identity and access management solution. Learn how to confifgure a docker image to create your own custom docker image using dockerfile. Oct 31, 2020 sudo docker build -t tag-demo:my-ubuntu. Tagging the Image directly. You can also tag an Image directly using the tag sub-command. Sudo docker tag / You can see that the new tag has been assigned to the Image. While Pulling an Image. You can pull a Docker Image using the pull sub-command. You can specify the.
In this tutorial, you will learn how to pull an official image from the Docker repository and customize it according to your own requirements. And then you can run and verify the custom docker image.
Creating custom docker image
So, in this example, you’ll be using an Alpine Linux image that does not include the Vim editor by default. You’ll modify this Docker image to create a new docker image of Alpine Linux that includes Vim editor by default. It cannot get any simpler than this. can it?
If you have not already, please install Docker on Ubuntu or whichever Linux distribution you are using. Make sure to add yourself to the docker group so that you can run docker without sudo.
You’ll need active internet connection for downloading the base docker image.
Step 1: Get docker image [optional]
I chose Alpine Linux in this example because it is really small. The Alpine docker image is hardly 5 MB in size, can you believe it? It’s the perfect Linux distribution for containerization.
This step is optional. I included it show that you can compare it with the customized docker image.
Pull the latest docker image of Alpine Linux using docker pull command:
Step 2: Create Dockerfile with the needed customization
Now let’s create a new empty file named Dockerfile using touch command.
Now you need to edit this file and these three lines to it and save it. You can use an edition like Vim or Nano or use cat command to add these lines to the Dockerfile.
What you are doing here is to create a new docker image by downloading the latest Alpine docker image from the Docker Hub.
Like apt, Alpine uses apk package manager. So the next two commands are basically telling Alpine linux to update the available package cache (apk update) and then install Vim (apk add vim).
As you can see, with RUN in Dockerfile, you can customize your base docker image by running specific commands.
Step 3: Create the custom docker image with Dockerfile
The command to build the custom image from the Dockerfile looks like this:
With the -t tag, you specify the name of your custom docker image.
Considering that your Dockerfile is in your current directory, you can create the new docker image of Alpine Linux with Vim installed like this:
Get Docker Images
Let’s see the available Docker images on the system now:
You can see that the base docker image which was hardly 5 MB in size is now 33 MB with Vim installed on it (and the package cache updated).
Now, let’s verify that your modified docker images has vim installed by running a container from it:
Once you are inside the container, you can verify that Vim is installed by checking its version:
Exit the container by typing exit in the terminal. Stop the container, remove the container and remove the docker images (if you want to) to free up disk space.
Congrats! You just learned how to create your very own customized docker image.
I know it’s not a very extensive tutorial and you may have complex need. But this tutorial works as the first step towards understanding docker image customization.
I highly recommend reading more on Dockerfile to know what other options you have available for customizing docker images.
Get Docker Image Sha
If you have questions or suggestions, please leave a comment below.
|docker||The base command for the Docker CLI.|
Get Docker Image Tag
|docker image build||Build an image from a Dockerfile|
|docker image history||Show the history of an image|
|docker image import||Import the contents from a tarball to create a filesystem image|
|docker image inspect||Display detailed information on one or more images|
|docker image load||Load an image from a tar archive or STDIN|
|docker image ls||List images|
|docker image prune||Remove unused images|
|docker image pull||Pull an image or a repository from a registry|
|docker image push||Push an image or a repository to a registry|
|docker image rm||Remove one or more images|
|docker image save||Save one or more images to a tar archive (streamed to STDOUT by default)|
|docker image tag||Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE|