Docker, which is used as a matter of course in development
However, the commands I use are limited, and there are things that should be dealt with with the mechanism of
It seems to be known, but not.
Docker, the learning content is summarized for each item
** Compact manual for Docker work **
I wanted to keep it as.
|Post number||Subtitle and access destination|
|1||Elementary / basic commands(* This article)|
|2||Mount and data persistence|
|4||Create a custom image|
If you find any mistakes or notices, we would appreciate it if you could point them out. If you find it helpful, I would be grateful if you could ** LGTM </ font> **.
Docker in this article? From to basic operations are summarized.
First of all, think about what
Docker is a typical software that realizes containers.
Although there are items described in various technical books and materials,
In a word, forcibly
I think it can be said.
--Since the environment is isolated, development is possible in each container.
--Easy to copy a container and run on another server (high portability)
--You can build the same environment (container) as long as you have a PC with
Docker Engine installed.
There are not many, but we will verify the disadvantages by comparison.
Docker EngineIn principle, if there is a security hole, there is a risk that the isolated part will come off.
Docker is a representative software that realizes a container environment.
Docker is software that runs on
If you install
Docker Engine on Linux, you will be able to run
On Mac and Windows, it can be executed by installing software called
After installing Docker Desktop, you can install and use the
The Docker container is the source of the container,
Docker image (* It may be expressed as an image below).
Obtain it from a registry such as
Docker Hub or use
Put the necessary data under the working directory and create your own customized image
There are two main methods, one is to create a Docker container.
Let's summarize the operation.
These are a series of flows, but it is common to execute from image acquisition to operation at once with docker run. Therefore, the explanation below is based on the assumption that docker run will be used.
There are some startup options that you often use when creating a docker run container.
|-d||Detach mode. Background execution separated from the container terminal|
|-i||Interactive mode. Container connection of standard input / output and standard error output|
|-t||Pseudo terminal(pseudo-tty)To assign.
A terminal that supports cursor movement, character deletion, and character input such as Ctrl.
|--name||Give the container a name. If not specified, the container name will be random.|
|-p||Map port numbers
(Host port number:Container port number)
|-v||volume:Volume refers to data that can be persisted.
Mount a volume of container data
(Host directory: Container directory)
|-rm||Option to destroy the container after execution is complete
It is convenient to set it as a container for test operation.
--- If it is, it is connected to the Docker container (executes the program in the container) --- If it is dit, the program of Docker host is executed (the container is running behind the scenes) --Attach is a Docker container connection --Detach is a connection such as a program (shell) of the Docker host and is not connected to the Docker container. --- It can be switched to detach by pressing [CTRL] + [P], [CTRL] + [Q] in order when connecting.
Accepts the request from the browser, Host 8080 opens, and via container 80 You'll get to Apache's public settings.
The current directory of the host is mounted on the container.
(* I would like to explain the mount again in Manual 2.
This is a backup image.)
In that case, you can specify it as an environment variable with
-v" $ PWD ": / usr / local / apache2 / htdocs
docker run --name my-apache-app -dit -p 8080:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
The following two types of commands can be used to connect to a container and perform maintenance.
|command||Container state||State at the end of the shell||Command example|
|docker run||Stopping||End of container||docker run --name my-apache-app -it httpd:2.4 /bin/bash|
|docker exec||During operation||Stay in operation||docker exec -it my-appache-app /bin/bash|
In most cases you should use docker exec. If you execute the above command, you can put it in bash below.
docker exec -it my-apache-app bash
❯ docker exec -it my-apache-app bash root@8c72c18e9169:/usr/local/apache2# ls -a . .. bin build cgi-bin conf error htdocs icons include logs modules