覆盖docker入口点

时间:2017-09-08 00:10:26

标签: docker docker-compose dockerfile

我有一个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命令,并且构建了图像。

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

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

每个web和redis容器都需要具有需要在其中设置的公共环境变量。我不想在dockerfile中设置它们,因为图像将被构建一次。

我想在构建堆栈时设置它们。如何共享2个容器之间的公共环境变量?有没有办法覆盖entrypoint.sh文件?

1 个答案:

答案 0 :(得分:0)

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

一种可能的解决方案是从主机环境传递env var:

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

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

相关问题