Docker-compose detailed and sample code _docker

Source: Internet
Author: User
Tags docker run

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.