Today I Learned (March 27, 2024)

How to define a specific shell to run RUN scripts in a Dockerfile

FROM ubuntu
SHELL ["/bin/bash", "-c"]
# ...

:link: Dockerfile SHELL directive

How to dynamically load config from a .env file during docker build

FROM ubuntu
SHELL ["/bin/bash", "-c"] # or, any other shell with a command to source env variables
# ...
RUN source .env && echo "foo: $FOO"


# .env
  • :warning: Requires BASH as shell or any shell that has a command similar to source
  • :information_source: Obviously, this makes only sense if you have a lot of configuration properties and don’t want to add an ARG directive for all of them; or, if you want to be able to load different configs depending on some other configuration property (like processor architecture).

How to always get output from a Dockerfile RUN directive

docker build \
  --no-cache # prevents using cached layers
  --progress=plain # show container output

:link: docker build --progress

How to run multiple container scanning jobs via the GitLab container_scanning template

:link: How to dynamically scan multiple container images in GitLab