As an exameple with the RUN
statement, if my code is:
RUN apt-get update
RUN apt-get install git
RUN apt-get clean
I can do:
RUN apt-get update && apt-get install git && apt-get clean
If my ENV is:
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_USER postgres
ENV POSTGRES_DB postgres
ENV POSTGRES_HOST db
How can I combine ENV statement in one line?
Dockerfile provides a dedicated variable type ENV to create an environment variable. We can access ENV values during the build, as well as once the container runs.
With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.
ENV is mainly meant to provide default values for your future environment variables. Running dockerized applications can access environment variables. It's a great way to pass configuration values to your project. ARG values are not available after the image is built.
Example from the Dockerfile reference
https://docs.docker.com/engine/reference/builder/#env
ENV myName="John Doe" myDog=Rex\ The\ Dog \
myCat=fluffy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With