――Since I usually develop in the docker environment, I have summarized the commands I usually use. --Scheduled to be updated at any time.
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.
docker-compose stop
Stop execution without deleting the container.
To resume, docker-compose start
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.
docker-compose ps
You can refer to the information of the running container.
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.
https://matsuand.github.io/docs.docker.jp.onthefly/compose/reference/ https://qiita.com/tegnike/items/bcdcee0320e11a928d46
Recommended Posts