・ Minutes of Docker operation.
mkdir <build context name>
-The build context is the folder that is the source of the image when creating a docker image.
cd <build context name>
-Set the current directory to the build context state
touch Dockerfile
-Create a text file called Dockerfile in the build context (this is a naming convention) -The command written in this is executed and an image is created (editing method is omitted because I will write a separate article)
docker build .
-"." Means the current directory (image creation is executed using the Dockerfile in the current directory) -Since the name and TAG are not specified, the image "none" is created. ・ Called dangling image
** [When explicitly specifying Dockerfile] **
docker build -f docker -f <Dockerfile path/name>
--F is an option to explicitly specify a Dockerfile -Enter the appropriate path and file name in the <Dockerfile path/name> part.
** [When creating by specifying the name and TAG] **
docker build -t <image name>:<TAG> .
-T is an option to create an image with a name
・ The
docker run <image name>
-Specify the image name that is the source of the container you want to create and execute run -As explained in # 1, this will exit the container after executing the default command.
** [Overwrite the default command after run] **
docker run <image name> <Overwrite command>
-Execute the overwrite command instead of the default command -In this case, after executing the overwrite command, exit and exit from the container. -The default command can be confirmed from Command of docker ps -a after executing run. -If you overwrite, the Command specified here will be displayed.
** [Description to remain in the container after running] **
docker run -it <image name> bash
-Now stays in the container without exiting after launching the container -Therefore, the description before execution of the terminal changes as follows.
root@xxxxxxxxxxx:/#
・ This means that you can now access the OS on Container through bash. -By default, it becomes the root user after starting the container. -The process of exiting from Continaer by exit is not executed. -When exiting the container, execute the following to return to the terminal state of the Host.
exit
docker run -it <image name> bash
-Commands that are often used to describe things that remain in the container after a run ・ Overlay -i and -t -it ・ Each has the following meanings
○-i ・ Input is possible -Command to connect STDIN (input ch) from HOST to container -If there is no connection, the input will only be transmitted to the Host, so the instructions will not reach the container.
[What is ch] ・ There are three types: "STDIN", "STDOUT", and "STDERR". ・ STDIN: ch for connecting keyboard input to the program -STDOUT, STDERR: ch to output the program result to the monitor
○-t ・ Terminal display becomes beautiful (prety) -Command storage can also be used
Recommended Posts