Use docker-compose to deploy the development environment

Source: Internet
Author: User
Functions of docker-compose

Docker-comopse can help us quickly build a development environment. For example, you can deploy redis, MongoDB, rabbitmq, MySQL, Eureka, and configserver on the local machine once, and then let them be the basis of other projects, which can be implemented.

Communication between containers-links

Since each docker instance is a closed environment, it cannot be shared by default, that is, your rabbit container cannot connect to your redis container, your configserver cannot connect to your Eureka container. If you want to allow data communication between them, you need to setlinksWhen connecting to the Local Machine (host machine), you can use localhost and port to access these containers.

Startup sequence-depends_on

For the startup sequence, for example, if your configserver depends on Eureka and you want to start the dependent container before running yourself, you can use the depends_on attribute to implement this, of course, it is only the starting order, and it cannot be guaranteed that the service will start the other one when it comes. The solution is to useRetry upon failureMechanismrestart: on-failureWhen the configserver fails, you can restart until it is successful (the master is until Eureka is started ).

Container and container must communicate with each other by service name

If we want to deploy a specific project in docker-compose and want to access other services, we need to use the service name defined in docker-compose instead of localhost, because when your container is up, its localhost is its own container instead of the host machine. If you want to access the container, you can uselocalhostThis is already mentioned in the previous article.

The following is an example of how to deploy the development environment.
Version: "3.3" services: # configurations related to public components MongoDB: Image: Mongo: 3.4.10 ports:-"27017: 27017" networks:-dev volumes:-pai_data: /data/DB redis: Image: redis: 3.2-Alpine networks:-dev ports:-"6379: 6379" volumes:-redis_data:/Data Rabbit: Image: rabbitmq: 3.6.10-management-Alpine hostname: Rabbit ports:-"5672: 5672"-"15672: 15672"-"61613: 61613" networks:-dev environment: rabbitmq_default_vhost: pilipa volumes: -rabbitmq_data:/var/lib/rabbitmq eurekaserver: Build :. /springcloud/Eureka-server restart: On-failure ports:-"8761: 8761"-"8762: 8762" networks:-dev configserver: Build :. /springcloud/config-server restart: On-failure ports:-"8888: 8888"-"8889: 8889" networks:-dev depends_on:-eurekaserver # dependent service links: -eurekaserver environment: spring_profiles_active: devops volumes:-/users/Lind. zhang/project/config-repo:/config_repo # The front is the local path, and the back is the path in the container. In configserver, the following container path is configured.
Start and update
  1. Image first
docker-compose build
  1. Restart the service
Docker-Compose up-D #-D is run in the background
  1. Stop Service
docker-compose down
  1. View container logs
Docker logs-F container ID

I hope this article will help you!

Use docker-compose to deploy the development environment

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.