[Docker] Operation up to container creation # 2

Purpose of this post

・ Minutes of Docker operation.


Teaching materials used for learning

I used Udemy's ["Docker course taught by US AI developers from scratch"](https://www.udemy.com/course/aidocker/) as a teaching material.

○ Create container (2. When creating image)

○ Creating build context

mkdir <build context name>

-The build context is the folder that is the source of the image when creating a docker image.

○ Move to build context

cd <build context name>

-Set the current directory to the build context state

○ Creating and editing Dockerfile

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)

○ Creating an image

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 part is usually written as latest.

○ Creating a container

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

What is ○ -it?

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

[Docker] Operation up to container creation # 2
Introduction to Linux Container / Docker (Part 1)
Pass environment variables to docker container
Docker push to GitHub Container Registry (ghcr.io)
[Docker] Copy files from docker container to host
Docker container build fails to install php-radis
Introduction to Docker / Kubernetes Practical Container Development
Docker operation memo
Small Docker container
How to get a heapdump from a Docker container
Copy files from docker container to host (docker cp)
I made a Docker container to run Maven
Cache Gradle dependent files to speed up docker build
[Introduction to Docker x ECS] ECS deployment with docker compose up
Steps to push Docker image to GitHub Container Registry (ghcr.io)
Create a Docker container to convert EPS to PGF source
Road to REPL (?) Creation (3)
How to install Docker
[Practice! ] Introduction of JFrame (explaining up to screen creation)
Docker container usage scene
Road to REPL (?) Creation (1)
Push Docker images from GitHub Actions to GitHub Container Registry
Road to REPL (?) Creation (2)
List of Docker commands that I often use (container operation)
Wait for the container service to start with docker healthcheck
[Docker] How to access the host from inside the container. http://host.docker.internal:
If Pikachu counts up to 100
About simple operation of Docker
Migrating from vargrant to docker
Set up GitLab with docker
How to set Docker nginx
CI / CD Docker container monitoring
Athrill's Docker container minimization procedure
Minimal Workflow to push Docker image to Github Container Registry with Github Actions
[GCP] Until you push the local Docker image to the Container Registry