I have a non-critical Docker Compose project where the Traefik rules vary acceptably between dev and production (I need Lets Encrypt on prod, but not on dev). I am using the [file]
config provider.
Currently I am creating separate builds for dev and prod, thus:
# This is fetched from the Compose config
ARG BUILD_NAME
RUN if [ "$BUILD_NAME" == "prod" ]; then \
echo Compiling prod config... ; \
sh /root/compile/prod.sh > /etc/traefik/traefik.toml ; \
else \
echo Compiling dev config... ; \
sh /root/compile/dev.sh > /etc/traefik/traefik.toml ; \
fi
While this project is not enormously important, per-env builds is a bit hacky, and I'd rather go with the standard container approach of one image for all environments.
To do that, I was thinking of doing something like this:
FROM traefik:1.7
# This is set in the Docker Compose config
ENV ENV_NAME
# Let's have a sig handler
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init
COPY docker/traefik/start.sh /root/start.sh
ENTRYPOINT ["/usr/local/bin/dumb-init", "--"]
CMD ["/root/start.sh"]
The start.sh
would have something that would run my "compile" shell command at run time (this selects pieces of config based on the environment). However, the official Traefik images do not run a shell - there are a compiled blob from Go source - so this won't work. Is there a env var by which /etc/traefik/traefik.toml
can be changed, or an industry standard way of doing this in Docker?
I did think of using volumes, but that means the container won't "plug-n-play" without additional set up - I like that it is currently self-contained. However, I may use that if there is no alternative. I could run the config "compiler" on the host.
Another approach is to install Traefik in an image that has a shell - maybe it would work with Alpine. I am not sure how I feel about that - removing the shell is a good security feature, so I am hesitant to add it back in, even if I don't think it can be easily exploited.