Yesterday in this mini-guide I told you about how to install Docker, the well-known open-source platform for managing Linux containers. Today we continue on the path traced widening the discussion and introducing the Dockerfile. These text files contain the list of instructions used by Docker for the build.
Dockerfile: custom images for Docker
This technology is widespread in the business sector. Often, it is preferred to classic virtualization because it offers maximum portability, configurability, and isolation. Docker makes it possible to quickly and easily deploy a Linux environment. In today's mini-guide, we will see just how to create a personalized image, among those available in the official repository.
In the example, the Alpine Linux image will be used, it weighs only 5MB. Since it does not contain Vim by default, our personalization will be just to add the text editor. Let's see how.
Retrieve the image of Alpine Linux from Docker Hub: docker pull alpine
Create the Dockerfile: touch Dockerfile, and modify it by adding these instructions:
FROM alpine:latest RUN apk update
RUN apk add vim
Go to the directory where you created the Dockerfile and create your personalized image:
docker build -t alpine-vim . //alpine-vim is the custom name, the point is the current directory
To check which images are present on our system, type in the docker images terminal. The output will look like this:
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine-vim latest fa8255cf0de0 5 seconds ago 33.9MB
alpine latest a187dde48cd2 3 weeks ago 5.6MB
Now starting the container with:
docker container run -ti alpine-vim /bin/sh
we can verify the correct implementation of Vim, checking its version: vim –version.
To deepen your knowledge on Dockerfile functioning, I refer you to the relative reference guide. Also on the official website of the open-source project, there is also a useful page of best practices.
0 Comments