docker memo

Introduction

In this article, I wrote down the commands I often used in docker for myself.

environment

Get Docker image

Get the image from Docker Hub etc.

docker pull ubuntu

Check the image

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.

Delete image

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.

Create image from Dockerfile

docker build -t [image name]:[TAG name] [Dockerfile directory] 

Create image from container (stopped)

docker commit [Container name or container ID] [image name]:[TAG name]

Start container

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 =

Checking the container

docker ps 

Show everything stopped with docker ps -a Show container ID including containers stopped with docker ps -aq

Stop, restart, delete container

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 container

Log in to the created container and start the shell.

docker exec -it [Container name or container ID] bash

Get out of the container

You can exit by typing Ctrl + D or exit.

root@b789a85f6d39:/# exit

Log output

Output the log output by the docker application and see it.

docker logs [Container name or container ID]

Confirmation of container information

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

docker memo
docker tutorial (memo)
Docker operation memo
Docker command memo
[Memo] docker summary
Docker x Rails 6 (memo)
docker inspect --format memo
Docker Machine command memo
docker
MySQL 5.7 (Docker) environment construction memo
Redmine (Docker) environment construction memo
Installing and building Docker (memo)
Integer memo
kubernetes + docker
spring × docker
About Docker
Lombok memo
Docker Intellij
Dockerfile memo
Iterator memo
Docker basics
corretto memo
Java memo
AWS memo
Docker installation
About Docker
Docker command
Docker memorandum
Understand Docker
Docker execution memo summarized for myself
Docker memorandum
Dcokerfile memo
Ruby memo
Memo Stream
Install Docker with WSL2 Memo ([Part 2] Docker introduction)
Spring retrospective memo
java anything memo
primary key memo
What is Docker?
Docker basic summary
Stream API memo
Technical memorandum (Docker)
Docker + Laravel + Codeception
Liberty on Docker
[Memo] Create a CentOS 8 environment easily with Docker
[wip] Docker notes
Memorandum docker command
Eclipse trick memo
Java Silver memo
java, maven memo
Docker command list
Environment construction command memo with Docker on AWS
JavaParser usage memo
What is Docker
Docker + Java + SpringBoot WEB development hands-on attendance memo (2019/08/19)
docker volume checked
docker basic command
Docker basic commands
SpringBoot-JPA-Hibernate addictive memo
Kubernetes/container-related standardization memo
Java SE 7 memo