简体   繁体   English

提高我的docker-compose.yaml的适应性

[英]Improving the adaptability of my docker-compose.yaml

I am using docker-compose for my open-source web application.我正在为我的开源 web 应用程序使用 docker-compose。 In the process of publishing my project on github I wanted to make my docker-compose.yaml file easier to understand and adapt.在 github 上发布我的项目的过程中,我想让我的 docker-compose.yaml 文件更容易理解和适应。 I'm still a beginner with Docker but the file works as intended.我仍然是 Docker 的初学者,但该文件按预期工作。 I just want to improve the readability and changeability of the volumes used by the containers.我只是想提高容器使用的卷的可读性和可变性。 The values a/large/directory/or/disk:/var/lib/postgresql/data and /another/large/disk/:/something will most likely need to be adapted to the system the user is running my application on.a/large/directory/or/disk:/var/lib/postgresql/data/another/large/disk/:/something很可能需要适应用户运行我的应用程序的系统。 Can I introduce variables for these?我可以为这些引入变量吗? How can I make it more obvious that these values are to be changed by the person running my application?我怎样才能更清楚地表明这些值将由运行我的应用程序的人更改?

My current docker-compose.yaml file我当前的 docker-compose.yaml 文件

version: '3'
services:
  postgres:
    image: postgres:latest
    restart: always
    expose:
      - 5432
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'password'
      POSTGRES_DB: 'sample'
    volumes:
      - /a/large/directory/or/disk:/var/lib/postgresql/data
    networks:
      - mynetwork
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: 'db'
      MYSQL_USER: 'user'
      MYSQL_PASSWORD: 'password'
      MYSQL_ROOT_PASSWORD: 'password'
    expose:
      - 3306
    ports:
      - 3306:3306
    volumes:
      - ~/data/mysql:/var/lib/mysql
    networks:
      - mynetwork
    depends_on:
      - postgres
  core:
    restart: always
    build: core/
    environment:
      SPRING_APPLICATION_JSON: '{
        "database.postgres.url": "postgres:5432/sample",
        "database.postgres.user": "postgres",
        "database.postgres.password": "password",
        "database.mysql.host": "mysql",
        "database.mysql.user": "root",
        "database.mysql.password": "password"
      }'
    volumes:
      - ~/data/core:/var
      - /another/large/disk/:/something  
    networks:
      - mynetwork
    depends_on:
      - mysql
    ports:
      - 8080:8080
  web:
    restart: always
    build: web/
    networks:
      - mynetwork
    depends_on:
      - core
    ports:
      - 3000:3000
networks:
  mynetwork:
    driver: bridge
volumes:
    myvolume:

(I'd also appreciate any other suggestions for improvements to my file!) (对于改进我的文件的任何其他建议,我也将不胜感激!)

Docker Compose supports variable interpolation. Docker Compose 支持变量插值。 But then you need to document those values, and people might just assume docker compose up and have it work without extra setup.但是随后您需要记录这些值,人们可能只是假设docker compose up并让它在没有额外设置的情况下工作。

Compose typically isn't used for production deployment, so you wouldn't use a real volume. Compose 通常不用于生产部署,因此您不会使用真实的卷。 That being said, you can simply use relative directories rather than home folder or absolute path ( ./data/app:/mount ) to the file itself, or a Docker managed volume.话虽如此,您可以简单地使用相对目录而不是主文件夹或绝对路径 ( ./data/app:/mount ) 到文件本身,或 Docker 托管卷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM