[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

I want to do this! Reverse lookup docker command when

GRED Web tampering check Cloud

Hello.
I'm Mandai, in charge of Wild on the development team.

I often forget about docker commands, so I wrote this out of anger.
I'll never forget this.


 

I want to get a list of docker images

docker images

 

I want to get a list of docker containers

# Only currently running docker containers docker ps # All including stopped docker containers docker ps -a # Display only docker container ID docker ps -q

 
"docker ps -q" is useless as a single item, but it is useful when deleting docker containers in bulk.

It may be difficult to imagine the difference between a docker image and a docker container at first, but the relationship is similar to that between a physical CD and an ISO file (it's hard to understand).

 

Start a docker container with a name

docker run --name [container name]

 
If you give a name to a docker container, to start a docker container with the same name, you must remove the docker container with the "docker rm" command.

 

Share files between docker container and host

docker run -v [directory path on host side]:[directory path inside docker container]

 

Port forward the docker container port so that it can also be used on the host side

docker run -p [host side port number]:[docker container port number]

 

Connect docker containers

docker run -link [docker container name or ID][:[alias]]

 
Aliases are useful if you haven't named your docker container, or if you have a very long docker container name.

The mechanism is simple using hosts, and if you compare the hosts files, it will look like the following.

# Start the MySQL container to connect $ docker run -d --name test -e MYSQL_ROOT_PASSWORD=root mysql:latest 529c5facaed9694dbcb36e9e3d3eae0350e26e182f70c72b06d2914dcf8c0222 # Start the docker container by specifying the name and alias for the link destination $ docker run - it --link test: db php:latest cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6- allrouters 172.17.0.3 db 529c5facaed9 test 172.17.0.4 ffae57a81bc1 # Start the docker container by specifying only the name in the link destination $ docker run -it --link test php:latest cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.17.0.3 test 529c5facaed9 172.17.0.4 128c598dea8a

 
The difference is whether or not the alias is listed in hosts.

 

Start a docker container in detached mode

docker run -d [docker image name]


 Detach mode is a state in which the program runs in the background without entering the container.
I totally thought it was Demon's d.

 

Start a docker container in the foreground and execute any command

docker run [docker image name] [command] 

 

Start docker container in foreground and attach to docker container

docker run -it [docker image name] [any shell such as /bin/bash]


 -i option attaches STDIN (standard input). In other words, input from the console will flow into the specified docker container.
If you type "docker run -i hogehoge /bin/bash", you can run the console command, but it will not be reflected on the screen.

The -t option assigns a TTY to the docker container. Without this, you will not be able to see the console inside the docker container even if you attach it.
If you type "docker run -t hogehoge /bin/bash", you can see the prompt inside the docker container, but the input you enter will not be reflected on the screen.

Therefore, in order to work inside a docker container, both of the above two options are required.

 

Set environment variables inside docker container at startup

docker run -e [variable name=value]

 
You can specify the mysql root password etc. with this.

docker run -e MYSQL_ROOT_PASSWORD=root

 

Attach to a running docker container

docker attach [docker container ID]

 
To detach, return to the host using the shortcut key CTRL + P, Q inside the docker container.

 

I want to run a shell command inside a docker container

docker exec [docker container ID] [shell to start, such as /bin/bash]

 

I want to stop the docker container

docker stop [docker container ID]

 

I want to delete the docker container

docker rm [docker container ID]

 

I want to delete all docker containers

docker rm $(docker ps -aq)

 
This is how to get the ID of the docker container using a subshell. The -q option of docker ps is the most useful.

 

I want to delete the docker image

docker rmi [docker image name]

 

I want to know information about docker containers

docker inspect [docker container ID]

 

If you want to get the IP address used by the docker container (additional information is also included, but the purpose is achieved)

docker inspect [docker container ID] | grep IPAddress

 

 
That's it.

If you found this article helpful , please give it a like!
2
Loading...
2 votes, average: 1.00 / 12
7,367
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.