A tool for defining and running multi-container docker applications. It is often used to set up a development environment or an automated test execution environment. As a usage, by describing the definitions of web server, DB server, cache server, etc. in one yml file, you can start all the containers required for application execution based on the yml file. yml is a format for expressing structured data, and it can be described intuitively even if you have never used yml. You can understand the structure by looking at the file.
1 Prepare ** Dockerfile ** or ** image to use ** on Docker Hub etc. 2 Define ** docker-compose.yml ** Write the startup settings for each container. This is like specifying an image name and various flags with the docker run command. 3 Run ** docker-compose up ** Specify docker-compose up in the directory where docker-compose is located. However, if it is left as it is, it will be executed in the foreground, so it is often executed by detaching with the -d option. When executed, each container will be executed according to the definition of docker-compose.yml.
docker-compose.yml
version: '3' -#docker-Compose file format version
services:
web: -#Service name, any name can be given
build: . -#docker-compose.The build context is the same directory as yml. So you need to create a dockerfile for your web service in the same directory as your yml file
ports: -#Indicates the port to be exposed to the outside of the container and the port to be mapped.
- "5000:5000"
volumes:
- .:/code -#docker with bind mount-compose.The directory where yml exists is the container/Mounted in the code directory.
- logvolume01:/var/log -#The volume of logvolume01 defined in volumes is the volume of the web service container./var/Mounted on log.
links:
- redis -#I'm setting up a link from a web service to a redis service
redis:
image: redis -#The redis service simply launches a container using a redis image.
volumes:
logvolume01 -#If you want to mount a named volume, you need to define it in volumes.
Expressly{}However, it is not necessary to write it. When writing settings such as driver to be used for volume,
You can continue to write the settings under the volume name, but if you simply use the default volume, no settings are required.
% docker-compose -v
docker-compose version 1.26.2, build eefe0d31
If downloaded, the docker-compose version will be displayed.
Recommended Posts