The real strength of Docker is that it can adapt the basic docker’s image to your needs. This allows you to quickly and easily implement a custom Linux environment by running the Container from this custom Docker image.
Docker offers an easy way to customize a Docker image and create your own personalized image using the Docker file.
In this lesson, you will learn how to extract the official image from the Docker repository and adapt it to your own needs. You can then launch and examine the custom docker image.
Creating a custom imageDocker
So in this example you are using an Alpine Linux image that does not contain the default Vim editor. You will modify this image to create a new Alpine Linux docker image that contains the default Vim editor. Nothing’s easier. Really?
If you haven’t already done so, install the Docker on Ubuntu or any other Linux distribution you use. Make sure you add yourself to the dockworker group, so you can let the dockworker walk without sudo.
You must have an active internet connection to download the image of the base dock.
Step 1: Retrieve dock figure [Optional]
In this example I chose Alpine Linux because it is very small. Alpine Docker’s image size is barely 5 MB, can you believe it? This is the ideal Linux distribution for containerization.
This step is optional. I turned it on to show that it’s similar to a modified image of the Docker.
Unpack the last image of the Alpine Linux docker with the pull-docker command :
Step 2: Create an anchor file with the desired parameter
Now let’s create a new blank file named Dockerfile using the touch command.
Touch the Docker file
You need to edit and save this file and these three lines now. You can use changes such as Vim or Nano or use the cat command to add these lines to the Docker file.
OF ALPINE: Add latest update
RUN apk vim
What you are doing here is to create a new image of the Docker by uploading the latest image of the Alpine Docker to the Docker Hub.
Like Apt, Alpine uses the apk package manager. So, the following two commands tell Alpine linux to update the cache of available packages (apk update) and to install Vim (apk add vim)
As you can see, RUN in the Dockerfile allows you to change the appearance of the base docker by executing certain commands.
Step 3: Create a custom Docker image using the Dockerfile
The command to create a custom image of a Dockerfile looks like this:
build a docker -t new_docker_image_name PATH_to_Dockerfile
Use the -t tag to specify the name of your custom Docker image.
Assuming that your docker file is in the current directory, you can create a new image of the Alpine Linux docker with Vim installed:
Meeting on the quay -t alpine-met-vim.
Let’s take a look at the Docker images available on the system:
[email protected]:~$ pictures of
IND Alpine Vima
Alpine last fa8255cf0de0 5 seconds ago 33.9MB
Alpine last a187dde48cd2 3 weeks ago 5.6MB
You can see that the basic docker image, which used to be only 5MB, now has 33MB when Vim is installed (and the packet cache is updated).
Now let’s check if your modified docker images vim installed by booting up its container:
Dock Container Run – alpine screw / bin /sh
While you are in the container, you can check if Vim is installed by checking the version:
/ # vim — version
VIM – Vi IMproved 8.2 (2019 dec 12, compiled 12 2019 19:30:49)
, compiled by Alpine Linux
Leave the container by entering the exit of the terminal. Stop the container, remove the container and remove the images from the docker (if desired) to create space on the hard disk.
Congratulations! You’ve just learned how to create your own custom docker image.
I know it’s not a very comprehensive manual and you may have a difficult need. However, this tutorial is a first step in understanding how to set up the Docker image.
I strongly recommend that you read more about Dockerfile to discover the other options available to customize your Docker images.
If you have any questions or suggestions, please leave a comment below.
Did you like the article? Share with us and help us grow 🙂create docker image from scratch,dockerfile from existing image