Docker-compose Use Example
Using Docker to build a MySQL + Java service + Nginx, a total of 4 Docker containers, if used Docker run way a container to create very cumbersome. In order to create containers more efficiently, Docker introduced the Docker-compose tool to quickly fix the creation of a set of containers just by defining a docker-compose.yml file.
MySQL:
image:daocloud.io/yjmyzz/mysql-osx:latest
volumes:
-/mysql/db:/var/lib/mysql
ports:
-3306:3306
Environment:
-mysql_root_password=123456
Service1:
image:java:latest
Volumes:
-/java:/opt/app
expose:
-8080
#ports:
# -9081:8080
Links:
- Mysql:default
Command:java-jar/opt/app/spring-boot-rest-framework-1.0.0.jar
service2:
Image: Java:latest
Volumes:
-/java:/opt/app
expose:
-8080
#ports:
# -9,082:8,080
Links:
-Mysql:default
Command:java-jar/opt/app/spring-boot-rest-framework-1.0.0.jar
NGINX1:
image:nginx:latest
volumes:
-./nginx/html:/usr/share/nginx/html:ro
-./nginx/ Nginx.conf:/etc/nginx/nginx.conf:ro
-/nginx/conf.d:/etc/nginx/conf.d:ro
#expose:
# 80
ports:
-"80:80"
Links:
-Service1:service1
-Service2:service2
The content is not complex, the specific keyword description see the last reference article link in this article.
Question: Where is this file?
See the following directory structure:
Mysql-java-nginx
├──docker-compose.yml
├──java
│ └──spring-boot-rest-framework-1.0.0.jar
├──mysql
│ └──db
└──nginx
├──conf
├──conf.d
│ └──default.conf
├──html
│ └──index.html
└──nginx.conf
To create a container:
CD Mysql-java-nginx
docker-compose up
It's as simple as that. The creation of all containers, up is usually used for the first time, you can observe the terminal real-time output log content to determine whether the container started normal, if there is no problem, direct CTRL + C exit, and then
Docker-compose start
Start the container in a later way.
Other orders are:
Commands: Build- or Rebuild services help-on a command
kill containers
Logs View output from containers
Pause Pause Services
Port Print The public port for a port Bindin G
PS List containers
Pull pulls service images
Restart Restart Services
RM Remove stopped containers
run run a one-off command
scale Set number of containers for a servic E
start Start Services
Stop services
unpause unpause Services up Create and start containers
migrate-to-labels recreate containers to add labels
version show the Docker-compose Version Information
Basically read the name to know the meaning.
Reference articles:
https://docs.docker.com/compose/compose-file/
Thank you for reading, I hope to help you, thank you for your support for this site!