我有一个具有以下结构的项目:
PROJ SRC 应用 app.py manage.py 迁移 Dockerfile 泊坞窗,compose.yaml我的目标是从…运行迁移
如何使用第三个容器完成此任务?所以当你跑步的时候 docker-compose up 它将根据您想要的顺序启动并运行命令然后退出。关于路径,您可以在实际应用程序容器和迁移任务容器之间创建共享命名卷。例如:
docker-compose up
version: "3" services: base: build: . volumes: - .:/code env_file: - .env command: 'false' web: extends: service: base command: flask run --host=0.0.0.0 links: - "db" ports: - "5000:5000" depends_on: - db db: image: postgres:10 restart: always environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=app ports: - "5432:5432" expose: - 5432 migrations: extends: service: base command: python manage.py db upgrade depends_on: - db
其他说明:
links
expose
wait-for-it
wait-for
让我们尝试使用docker-compose.yml
--- version: "3" services: web: links: - "db" build: . ports: - "5000:5000" volumes: - .:/code entrypoint: - python - manage.py - db - upgrade depends_on: - db env_file: - .env db: image: postgres:10 restart: always environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - POSTGRES_DB=app ports: - "5432:5432" expose: - 5432