docker command personal summary

Overview

――Since I usually develop in the docker environment, I have summarized the commands I usually use. --Scheduled to be updated at any time.

Start-up

docker-compose up

Build, (re) create, start, and attach the container. The log is output to standard output. If the service settings or image are changed after the container is created, the above command detects the change and stops and regenerates the container. (volume is kept as it is)

docker-compose up -d

docker-compose up --detach Start the container in the background.

docker-compose build

Build the image needed to start the container. To change the contents of the Dockerfile or build directory, execute the above command and rebuild.

docker-compose build --no-cache

If there is an existing cache, it may not load the changed one, so add an option.

docker-compose up --build

It builds the image before starting the container.

Stop

docker-compose stop

Stop execution without deleting the container. To resume, docker-compose start

Stop / Delete

docker-compose down

Stop the container. Delete the container, network, volume and image created by the up command.

docker-compose down --rmi all --volumes

The above command when you want to recreate from scratch. Stop the container, delete the container, delete all the images used for all services, and delete the volume.

docker system prune —volume

Delete and initialize all networks, including images, volumes and caches.

Check the startup container

docker-compose ps

You can refer to the information of the running container.

Execute arbitrary command in docker environment

docker-compose exec app_name command

You can execute commands from outside the container inside the running container. Like rails c and rspec

docker-compose exec app_name /bin/bash

On the other hand, when you want to log in to the running container and operate it with bash, for example, start the container with docker-compose up -d and log in with the above command. You can also enter the container with docker exec -it container name / bin / bash. docker-compose manages multiple container applications, while docker manages a single container.

docker attach container name

When you want to debug with binding.pry, you need to attach it to the container separately from the terminal displaying the log.

reference

https://matsuand.github.io/docs.docker.jp.onthefly/compose/reference/ https://qiita.com/tegnike/items/bcdcee0320e11a928d46

Recommended Posts

docker command personal summary
Docker command summary
[Docker] Command summary
Docker command
Docker basic summary
Memorandum docker command
Docker command list
Heroku command summary
docker basic command
Docker command memorandum
[Docker] Command list
[Rails] Migration command summary
[Personal memo] try-catch summary
Docker Machine command memo
Java static [Personal summary]
docker error delete command
Docker command cheat sheet
Docker network (personal memorandum)
Decomposing the Docker run command. .. ..
Docker Compact Manual (1: Basic / Basic Command)
Summary
Summary of frequently used Docker commands
docker
Easy installation of Docker with snap (1 command)
Rails environment construction with Docker (personal apocalypse)
Launch docker container on EC2 (personal memorandum)
Summary of Docker understanding by beginners ② ~ docker-compose ~
[Java] Personal summary of conditional statements (basic)