Also, I'm going to leave Docker for a while, so I'd like to write a memorandum as well. This time, I will briefly introduce FROM, RUN, and CMD.
FROM The Dockerfile describes the FROM to determine the base image. When specifying the image of the latest version of ex.ubuntu
Until you get used to it, it's a good idea to specify one that has all the tools you need. Once you get used to it, you should consider adding the tools you want only with the OS.
RUN You can use this command to customize what your server needs to your liking.
ex. Create files test1.txt and test2.txt on the image OS
RUN touch test1.txt RUN touch test2.txt
It is possible to prepare the environment on the image OS by executing the
RUN command with multiple lines, but a layer is created for each
Please note that the image becomes larger as the number of layers increases.
If you need to use multiple commands to create layers, RUN, COPY, and ADD, use && to connect the commands. If one line becomes long, the Dockerfile will be hard to see, so start a new line with \ (backslash).
RUN apt-get update RUN apt-get install aaa RUN apt-get install bbb RUN apt-get install ccc
RUN apt-get update && apt-get install aaa bbb ccc
↓ As the number of installation packages increases, it becomes difficult to see, so arrange with line breaks.
RUN apt-get update && apt-get install \ aaa \ bbb \ ccc``` You need to enter the execution permission y interactively, so if you enter -y which means yes, the installation will run smoothly. #### **`Dockerfile`** ```docker RUN apt-get update && apt-get install \ aaa \ bbb \ ccc
When writing to install the tool with apt-get etc., aaa and bbb were installed successfully one by one, so connect them and write ccc and try ... and access to the network every time to get the execution result It will occur.
If you want to install the aaa bbb ccc tool
RUN apt-get install \ aaa \ bbb
Since this worked, if you continue to write ccc, the cache will not be used and everything will be fetched from the network.
RUN apt-get install \ aaa \ bbb \ ccc
↓ First, write in a different RUN.
RUN apt-get install \ aaa \ bbb RUN apt-get ccc
First of all, I will try to see if it works well by dividing the things to be added later. Hopefully you can eliminate the loss of a series of execution time from description by writing it on one line.
CMD -By writing at the end of the Dockerfile, you can specify the command to be executed by default in the container. CMD ["command", "parameter 1", "parameter 2", "parameter 3"] ex. Start Bash
FROM ... RUN ... CMD ["bin/bash"]
If you want to create an environment such as a simple web server with the commands introduced above: FROM, RUN, CMD, you will be able to create it. Docker is convenient, so please try it.