Learn more about docker image and Dockerfile FROM

2020-10-26_215138.png

Learn more about docker image and Dockerfile FROM

I had read through docker's Dockerfile lightly, but I thought it was necessary to ask the following again in order to understand it properly. Who is the docker image, what is the Dockerfile, and what is the FROM described in that Dockerfile?

What is a Dockerfile

Dockerfile best practices Docker-docs-ja 19.03 documentation

Dockerfile is a text file that describes all the instructions needed to build an image in order. For those who know it, the docker version of Makefile may be a good idea. The procedure for building a docker image is described in order according to a specific format and instruction group. In short, it is a text file that incorporates the construction of an environment called a docker image.

What is a layer?

The Docker image is made up of read-only layers that correspond to the instructions in the

Dockerfile. Each layer is a diff changed from the previous layer, and these layers are stacked. </ blockquote> What is the layer that suddenly appeared?

FROM ubuntu:18.04 COPY . /app RUN make /app CMD python /app/app.py
It says to create one layer for each of these instructions. When you run the
image and create a container, it adds a new writable layer (this is the "container layer") on top of the original layer. All changes to a running container, such as writing new files, editing existing files, deleting files, etc., are described within this writable container layer. In the above example, add a new layer to the "ubuntu: 18.04" layer with "COPY. / App" and "RUN make / app", and then use "CMD python /app/app.py" with python / app / app. It means that py creates an executed image. It may be easy to understand that the "ubuntu: 18.04" layer is overlaid with other layers.

What is build

In a nutshell, it's a command that builds a docker image according to the specified Dockerfile. For those who know this, the docker version of the make command may be just right.

mkdir myproject && cd myproject echo "hello" > hello echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile docker build -t helloapp:v1 .
In the above example, use BusyBox to create a "hello file" with cat. The Dockerfile that builds the image to be displayed is spit out, and the docker image is built according to the Dockerfile.

What is FROM in Dockerfile?

What is the FROM of a Dockerfile?

FROM ubuntu:18.04 COPY . /app RUN make /app CMD python /app/app.py
In this example earlier, FROM is described as "Create a layer from a Docker image on ubuntu: 18.04".
mkdir myproject && cd myproject echo "hello" > hello echo -e "FROM busybox\nCOPY /hello /\nRUN cat /hello" > Dockerfile docker build -t helloapp:v1 .
In this example, busybox is specified for FROM. Of course, busybox also has a docker image , and if you simply specify FROM busybox, it's latest. Image is specified.

For FROM ubuntu: 18.04

What about FROM ubuntu: 18.04? If FROM busybox and ":" are not specified, it will be the latest (latest), but what happens if ":" is added? Let's see Explanation of FROM .

FROM <image> [AS <name>] Or FROM <image>[:<tag>] [AS <name>] Or FROM <image>[@<digest>] [AS <name>] You can optionally give a name to the new build stage. This is done by the AS name of the FROM instruction. This name can be used in subsequent FROM and COPY --from = commands to refer to the image built during this build stage. Tag and digest settings are optional. If this is omitted, the default latest tag will be treated as specified. If no match for the value of tag is found, an error is returned. So, if you specify FROM ubuntu: 18.04, the image of ubuntu 18.04 tag will be specified. Specifically ubuntu Docker Images 18.04 , you can see how ubuntu: 18.04 docker image is created. Can be seen.
FROM scratch ADD ubuntu-bionic-core-cloudimg-amd64-root.tar.gz / Omission RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container CMD ["/bin/bash"]
Notice that it starts with FROM scratch as there is no base docker image.

Official recommended FROM

Dockerfile best practices Docker-docs-ja 19.03 documentation Recommendations are given in FROM description ..

Whenever possible, use the latest official image as the basis for your image. Our recommendation is the Alpine image. This is a very controlled but small (currently less than 5MB) Linux distribution.

What is an Alpine image?

A minimal Docker image based on Alpine Linux with a full package index and a size of only 5MB! The Alpine image is touted as . "We have access to a much more complete package repository than other BusyBox-based images, which makes Alpine Linux a great image base for utilities and production applications." As an example of actually adopting the Alpine image, the other day in the web server software Here is a caddy . Looking at the caddy Dockerfile of latest It starts with "FROM alpine: 3.12." alpine currently has "3.12.1, 3.12, 3" as the latest.

In summary

Who is the docker image, what is the Dockerfile, and what is the FROM described in that Dockerfile? A docker image is an image for a docker container built by the build command according to the specified Dockerfile. A Dockerfile is a text file that describes all the instructions required to build a docker image in order. FROM is the basis for writing in the Dockerfile. Normally, specify the docker image, but if there is not, write FROM scratch. The official recommendation is FROM Alpine.

Recommended Posts