Docker Stack 笔记
- 2020 年 10 月 17 日
- 筆記
- Docker Compose, Docker File, Docker Stack, Swarm
Docker Compose (Docker Stack)
image: Specify the image to start the container from. Can either be a repository/tag or a partial image ID.
If the image does not exist, Compose attempts to pull it, unless you have also specified build, in which case it builds it using the specified options and tags it with the specified tag.
deploy: (resource limits) This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.
depends_on: Express dependency between services. Service dependencies cause the following behaviors:
networks: Networks to join, referencing entries under the top-level networks key.
ports: (Port mapping) Either specify both ports (HOST:CONTAINER), or just the container port (an ephemeral host port is chosen).
environment: Environment variables with only a key are resolved to their values on the machine Compose is running on, which can be helpful for secret or host-specific values.
environment:
– SHOW=true
– SESSION_SECRET
volumes: bind mount, named volume
When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents. Volumes have several advantages over bind mounts.
The source of the mount. For bind mounts, this is the path to the file or directory on the Docker daemon host. May be specified as source or src.
The destination takes as its value the path where the file or directory is mounted in the container. May be specified as destination, dst, or target.
logging: The default driver json-file, has options to limit the amount of logs stored. To do this, use a key-value pair for maximum storage size and maximum number of files:
options:
max-size: “200k”
max-file: “10”
The example shown above would store log files until they reach a max-size of 200kB, and then rotate them. As logs grow beyond the max limits, older log files are removed to allow storage of new logs.
docker-stack.yml
# docker stack deploy -c docker-stack.yml version: "3.5" x-logging: &graylog-logging driver: gelf options: gelf-address: "udp://graylog-svc:12201" x-default-logging: &default-logging driver: json-file x-deploy: &default-limits resources: limits: memory: 256M x-environment: &rcs-config-server-url RCS_CONFIG_SERVER_URL=http://config-server:19050/config services: redis: image: "redis:latest" # logging: *graylog-logging deploy: *default-limits networks: - outside ports: - "6379:6379" volumes: - /u/docker/redis/config:/usr/local/etc/redis # service name: prime_config-server config-server: image: "dck0.prime/prime-rcs-config-server:${RCS_CONFIG_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits networks: - outside ports: - "19050:19050" environment: - RCS_CONFIG_SERVER_LOCATION=file:/assert/config - RCS_KEYSTORE_LOCATION=file:/assert/server.jks - RCS_KEYSTORE_ALIAS=sz-qa-env env_file: "$HOME/.ssh/rcs_keystore.env" volumes: - ./server.jks:/assert/server.jks:/ro - ~/workspace/devops/prime-config/qa/qa:/assert/config/:/ro pmc-backend: image: "dck0.prime/prime-management-console:${PMC_BACKEND_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server - redis networks: - outside ports: - "8283:8283" environment: - PMC_CONFIG_CLIENT_URL=http://config-server:19050/config - PMC_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true volumes: - /u/docker/nginx/html/logs/pmc:/prime/logs/pmc - /u/docker/nginx/html/upload:/opt/pmc/upload mission-mgr: image: "dck0.prime/prime-rcs-mission:${RCS_MISSION_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "19030:19030" - "16002:16002" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true - JPDA_ADDRESS=16002 - JPDA_TRANSPORT=dt_socket volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs - /u/docker/rcs/mission/script:/rcs/uploads/mission-script traffic-mgr: image: "dck0.prime/prime-rcs-traffic-manager:${RCS_TRAFFIC_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "19090:19090" - "16001:16001" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true - JPDA_ADDRESS=16001 - JPDA_TRANSPORT=dt_socket volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs battery-mgr: image: "dck0.prime/prime-rcs-battery-manager:${RCS_BATTERY_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "19040:19040" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs simulator-mgr: image: "dck0.prime/prime-rcs-simulator:${RCS_SIMULATOR_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "18010:18010" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs error-mgr: image: "dck0.prime/prime-rcs-error:${RCS_SIMULATOR_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "18040:18040" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 - APM_AGENT_ACTIVE=true volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs eshelf-mgr: image: "dck0.prime/prime-rcs-eshelf:${RCS_ESHELF_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "19110:19110" environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs path-plan: image: "dck0.prime/prime-rcs-path-plan:${RCS_PATH_PLAN_VERSION:-0.0.1-SNAPSHOT}" # logging: *graylog-logging deploy: *default-limits networks: - outside ports: - "18020:80" environment: - RCS_MISSION_SERVER=http://mission-mgr:19030 volumes: - /u/docker/nginx/html/logs/rcs:/RcsPathPlan/logs ticket-mgr: image: "dck0.prime/prime-web-service:latest" # logging: *graylog-logging deploy: *default-limits networks: - outside ports: - "3000:3000" # prime-rcs-authentication: # image: "dck0.prime/prime-rcs-authentication:0.0.1-SNAPSHOT" # # logging: *graylog-logging # deploy: *default-limits # networks: # - outside # ports: # - "8090:8090" # prime-rcs-auth2-web: # image: "dck0.prime/prime-rcs-auth2-web:0.0.1-SNAPSHOT" # # logging: *graylog-logging # deploy: *default-limits # networks: # - outside # ports: # - "8091:8091" asc-bridge: image: "dck0.prime/prime-asc-bridge:1.0-SNAPSHOT" # logging: *graylog-logging deploy: *default-limits depends_on: - config-server networks: - outside ports: - "19080:19080" volumes: - /u/docker/nginx/html/logs/rcs:/rcs/logs environment: - *rcs-config-server-url - RCS_CONFIG_CLIENT_PROFILE=qa - LOGBACK_LOGSTASH_URL=10.102.129.23:5044 networks: outside: external: true name: qa-subnet