编程知识 cdmana.com

5.docker- compose.yml file management

docker-compose file management

  1. sketch

    Compose  Is used to define and run multiple containers  Docker  Application tools .
    #  step 
    1.	 Use  Dockerfile  Define the environment of the application .
    2.	 Use  docker-compose.yml  Define the services that make up the application , So they can run together in an isolated environment .
    3.	 Last , perform  docker-compose up  Command to start and run the entire application .
    # yml Document components 
    version
    services
    networks
    volumes
    
    
  2. docker-compose.yml File example

    version: "3"
    services:
      eureka:
        image:  Mirror name :tag
        build: .
        env_file:
          - .env
        deploy:
          resources:
            limits:
              cpus: '1.50'
              memory: 3072M
        volumes:
          - /data/Log:/data/log
          - /etc/localtime:/etc/localtime
        environment:
          SKYWALKING_AGENT_SERVICE_NAME: eureka
        network_mode: "host"
        ports:
          - 1111:1111
    
  3. services The rules of writing

    • image
      #  Mirror image 
      services: 
        eureka: #  Custom service name 
          image:  Mirror name :tag #  Mirror image 
      #  The format is as follows 
      image: redis
      image: mysql:5.7.26
      image: 192.168.168.22/base/eureka:v1
    
    • build
      #  be based on Dockerfile, Appoint Dockerfile Location path 
      #  Absolute path 
      build: /path/build
      #  Relative paths 
      build: .
      #  Set context and directory 
      build:
        context: ../
        dockerfile: path/Dockerfile
      #  Specify environment variables 
      build: 
        context: .
        args:
          - key1=value1
          - key2=value2
    
    • env_file
      #  Specify profile 
      env_file: .env
      #  Be careful :  If and environment Instruction conflict , The latter shall prevail 
      #  Set up multiple 
      env_file:
        - .env
        - test.env
    
    • volumes
      #  Mount a directory or an existing data volume container 
      volumes:
        - /data/Log:/data/log #  Mount the data volume using an absolute path 
        - /var/lib/mysql #  Just specify a path ,Docker  It will automatically create a data volume 
        - ./log:/data/log #  Mount data volumes using relative paths 
        - datavolume:/var/lib/mysql # Named data volumes that already exist 
    
    • environment
      #  Set the mirror variable 
      environment:
        key1: value1
        key2: value2
       perhaps 
      environment:
        - key1=value1
        - key2=value2
    
    • network_mode
      #  Network mode  5 Kind of 
      network_mode: "host"
      network_mode: "bridge"
    
    • ports
      #  Port mapping 
      ports:
        - 1111:1111
        - 8889:8888
       # Port mapping : Container port 
    
    • depends_on
      #  The container depends on 
      depends_on:
        - eureka
        - db
    
    • deploy
      #  Specify the configuration associated with deploying and running services 
      #  children  resources
      deploy:
        resources:
          limits: #  We can't have more resources than we have now 
            cpus: '1.50'
            memory: 3072M
          reservations: #  Retain resources 
            cpus: '0.25'
            memory: 100M
    
    • other
       #  Other configuration 
       dns
       tmpfs
       container_name
    
  4. volumes

    #  Data volume 
    volumes:
      datavolume: 
    

版权声明
本文为[qms19]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225140542946e.html

Scroll to Top