覆盖docker入口点

我有一个dockerfile具有以下图像。

FROM python:3.4-alpine RUN apt-get update && apt-get install -y ENV TINI_VERSION v0.15.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini RUN chmod +x /tini COPY ./entrypoint.sh / ENTRYPOINT ["/tini", "--", "/entrypoint.sh"] 

entrypoint.sh有一些运行的bash命令,图像是build立的。

现在,我使用上面的图像生成使用docker-compose文件的多个容器。

 services: web: image: test/tutorials:latest ports: - "8000:8000" redis: image: test/tutorials:latest 

每个web和redis容器都需要有共同的环境variables,需要在其中设置。 我不想将它们设置在dockerfile中,因为图像将被构build一次。 我想在堆栈build立时设置它们。 如何共享2个容器之间的常见环境variables? 有没有办法来覆盖entrypoint.sh文件?

请参阅这里的文档: https : //docs.docker.com/compose/environment-variables/

一种可能的解决scheme是从宿主环境中传递你的envvariables:

 services: web: image: test/tutorials:latest ports: - "8000:8000" environment: - TINI_VERSION redis: image: test/tutorials:latest environment: - TINI_VERSION 

然后,您只需在使用docker docker-compose run之前在主机env中设置TINI_VERSION。 还可以在.env文件中设置默认值。