Process for making dockerfile

  docker, question

Recently, I read some knowledge about Docker, and I don’t understand the process of making dockerfile.

If you want to make a dockerfile based on Ubuntu that includes Nginx, MySQL, PHP and other services, my current process is as follows:

  • Docker run is a basic Ubuntu image

  • Update system dependency packages, such as apt-get update, and record commands executed in text documents

  • Install Nginx and record the steps performed by installing Nginx in a text document.

  • ….

It is equivalent to running the process once, recording all the executed commands, and then copying these steps into the dockerfile.

Personally, I feel it is wrong to do so. How do you do it? ?

That’s right. If you are very familiar with all processes, you can naturally write Dockerfile directly. However, this kind of thing cannot be absolutely guaranteed, especially the basic system image of Docker is mostly very compact, and some software dependency packages need to be downloaded and installed, so the process of building one by oneself through container practice is time consuming, but relatively speaking, it will save time than writing Dockerfile in fantasy.

Generally speaking, writing a Dockerfile is a process like this:

  1. Record the build order by rehearsing the installation process of the container.

  2. Summarize and optimize installation commands and write Dockerfile

  3. Try building a mirror using Dockerfile to check for problems

  4. Build the container through the built image to ensure that the programs in it can be used correctly.