Skip to content

Instantly share code, notes, and snippets.

@toddlers
Created July 27, 2016 11:24
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save toddlers/d57565644d860160c05fcb4364dbd16c to your computer and use it in GitHub Desktop.
Save toddlers/d57565644d860160c05fcb4364dbd16c to your computer and use it in GitHub Desktop.
using envsubst in Dockerfile
FROM ubuntu:trusty
RUN \
apt-get update \
&& apt-get -y install gettext-base \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV VALUE=foo
ENV VALUE1=boo
COPY config.txt source_config.txt
RUN envsubst < "source_config.txt" > "config.txt"
@mattdodge
Copy link

I don't think you'd be able to RUN the envsubst. Well I mean you can run it, but it won't have the environment variables that are passed when the container is launched, which is probably what you'd want otherwise you should use build args. Maybe you mean CMD on that last line instead of RUN?

@danilaplee
Copy link

I don't think you'd be able to RUN the envsubst. Well I mean you can run it, but it won't have the environment variables that are passed when the container is launched, which is probably what you'd want otherwise you should use build args. Maybe you mean CMD on that last line instead of RUN?

lol man :)

@Luckykarter
Copy link

You can run it, but must have it in the same line - so they will be in the same context.

RUN export VALUE=foo && \
    export VALUE1=$(cmd to get value1) && \
    envsubst < "source_config.txt" > "config.txt"

@saladinjake
Copy link

Update available packages in Debian

RUN apt-get update

CMD export VALUE=foo &&
export VALUE1=$(cmd to get value1) &&
envsubst < "source_config.txt" > "config.txt"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment