简体   繁体   English

如何使用别人的docker-compose?

[英]How to use docker-compose from another person?

I'm pretty new to the world of Docker, so I have the following scenario:我对 Docker 的世界还很陌生,所以我有以下场景:

  • Spring Boot application which depends to.. Spring 引导应用程序依赖于..
  • PostgreSQL PostgreSQL

and frontend requesting data from them.和前端向他们请求数据。

The Dockerfile in the Spring Boot app is: Spring Boot app中的Dockerfile为:

EXPOSE 8080
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

And the content of the docker-compose.yaml is:而docker-compose.yaml的内容是:

version: '3'

services:
  app:
    image: <user>/<repo>
    build: .
    ports:
      - "8080:8080"
    container_name: app_test
    depends_on:
      - db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/test
      - SPRING_DATASOURCE_USERNAME=test
      - SPRING_DATASOURCE_PASSWORD=test

  db:
    image: 'postgres:13.1-alpine'
    restart: always
    expose:
      - 5432
    ports:
      - "5433:5432"
    container_name: db_test
    environment:
      - POSTGRES_DB=test
      - POSTGRES_USER=test
      - POSTGRES_PASSWORD=test
    volumes:
      - db:/var/lib/postgresql/data
      - ./create-tables.sql:/docker-entrypoint-initdb.d/create-tables.sql
      - ./fill_tables.sql:/docker-entrypoint-initdb.d/fill_tables.sql
volumes:
    db:
      driver: local

As far as I understand in order to run the whole thing is required just to type docker-compose up and voila, it works.据我所知,为了运行整个程序,只需键入docker-compose可以了,瞧,它可以工作。 It pulls the image for the app from the docker-hub repo and same does for the image for the database.它从 docker-hub 存储库中提取应用程序的图像,对数据库的图像也是如此。

Here comes the thing.事情来了。 I'm working with another guy (front end), whose goal is to make requests to this API. So is it enough for him to just copy-paste this docker-compose.yaml file and write docker-compose up or there is another thing to be done?我正在和另一个人(前端)一起工作,他的目标是向这个 API 发出请求。所以他只复制粘贴这个 docker-compose.yaml 文件并写上 docker-compose 就足够了吗?或者还有另一件事要做?

How should docker-compose be used in teamwork? docker-compose在团队合作中应该如何使用?

Thanks in advance, if I have to make it more clear leave a comment!在此先感谢,如果我必须更清楚地发表评论!

Because of the build: .由于build: . keyword in your docker-compose in api service, running docker-compose up will search for the backend Dockerfile and build the image.api服务中输入 docker-compose 关键字,运行docker-compose up将搜索后端 Dockerfile 并构建镜像。 So, your teammate needs to get all the files you wrote.所以,你的队友需要得到你写的所有文件。
Another solution, which in my point of view is better, would be building the image by you and pushing it to docker.hub, so your teammate can just pull the image from there and run it on his/her system.另一种解决方案,在我看来更好,是由您构建映像并将其推送到 docker.hub,这样您的队友就可以从那里拉取映像并在他/她的系统上运行。 For this solution, this could be useful.对于此解决方案,可能很有用。
In case your not familiar with docker hub, read this quick start如果您不熟悉 docker 集线器,请阅读此快速入门

Your colleague will need:您的同事将需要:

  • The docker-compose.yml file itself docker-compose.yml文件本身
  • Any local files or directories named on the left-hand side of volumes: bind mounts volumes:绑定挂载
  • Any directories named in build: (or build: { context: } ) lines, if the images aren't pushed to a registrybuild: (or build: { context: } ) 行中命名的任何目录,如果图像没有被推送到注册表
  • Any data content contained in a named volume that isn't automatically recreated未自动重新创建的命名卷中包含的任何数据内容

If they have the docker-compose.yml file they can docker-compose pull the images named there, and Docker won't try to rebuild them.如果他们有docker-compose.yml文件,他们可以docker-compose pull那里命名的图像,Docker 不会尝试重建它们。

Named volumes are difficult to transfer between systems;命名卷很难在系统之间传输; see the Docker documentation on saving and restoring volumes .请参阅有关保存和恢复卷的 Docker 文档 Bind-mounted host directories are easier to transfer, but are much slower on non-Linux hosts.绑定挂载的主机目录更容易传输,但在非 Linux 主机上要慢得多。 Avoid using volumes for parts of your application code, including the Node library directory or static assets.避免对部分应用程序代码使用卷,包括 Node 库目录或 static 资产。

For this setup in particular, the one change I might consider making is using the postgres image 's environment variables to create the database, and then use your application's database migration system to create tables and seed data.特别是对于此设置,我可能考虑进行的一项更改是使用postgres图像的环境变量来创建数据库,然后使用应用程序的数据库迁移系统来创建表和种子数据。 This would avoid needing the two .sql files.这将避免需要两个.sql文件。 Beyond that, the only thing they need is the docker-compose.yml file.除此之外,他们唯一需要的是docker-compose.yml文件。

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

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