In this article, I wrote down the commands I often used in docker for myself.
Get the image from Docker Hub etc.
docker pull ubuntu
Get the acquired image with images.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-python latest 91d4b5ba1c2d 4 weeks ago 605MB
ubuntu 18.04 56def654ec22 8 weeks ago 63.2MB
In the above case, there are images called ubuntu and ubuntu-python.
docker rmi [imageID or image name]
If you want to delete ubuntu-python
docker rmi ubuntu-python
docker rmi 91d4b5ba1c2d
docker rmi 9
You can erase it with. Since the ID is a prefix match, the last command removes all images with image IDs starting with 9.
docker build -t [image name]:[TAG name] [Dockerfile directory]
docker commit [Container name or container ID] [image name]:[TAG name]
Start the container from the created image.
docker run -itd --name [Container name or container ID] [image name]
About frequently used options
--name [Container name] can be omitted, but it can be named randomly. -it Connect standard I / O to the container (when keying). -d Run container in background -p [Host Port]: [Container Port]
If you want to mount the volume when creating the container (The following example mounts the current directory)
docker run --name myubuntu -itd \
--mount type=volume,src=$(pwd),dst=/vol ubuntu /bin/bash
(-v [Absolute path of host DIR]: [Absolute path of container]) In the case of (-v) above, I don't know whether it is mounted by volume or bind. If you want to synchronize data between the host and the container (not recommended) --mount type = bind, src =
, dst = When you want to mount a volume in a container --mount type = volume, src = , dst =
docker ps
Show everything stopped with docker ps -a Show container ID including containers stopped with docker ps -aq
docker stop [Container name or container ID] #Stop
docker start [Container name or container ID] #restart
docker rm [Container name or container ID] #Delete
If you want to delete all the containers
docker rm $(docker ps -aq)
Log in to the created container and start the shell.
docker exec -it [Container name or container ID] bash
You can exit by typing Ctrl + D or exit.
root@b789a85f6d39:/# exit
Output the log output by the docker application and see it.
docker logs [Container name or container ID]
Get all information about the specified container.
docker inspect [Container name or container ID]
Basically, there is only some information, so Output pinpoint with --format option.
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' [Container name or container ID]
##Get the IP address assigned to the container
--format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' Get the IP Address in NetworkSettings.Networks.
Recommended Posts