Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I combine ENV statement in Dockerfile?

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?

like image 339
Avara Avatar asked Apr 21 '16 16:04

Avara


People also ask

Can I use ENV variable in Dockerfile?

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.

Can you have two from statements in Dockerfile?

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.

What does ENV do in Dockerfile?

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.


1 Answers

Example from the Dockerfile reference

https://docs.docker.com/engine/reference/builder/#env

ENV myName="John Doe" myDog=Rex\ The\ Dog \
    myCat=fluffy
like image 150
Xiongbing Jin Avatar answered Sep 23 '22 12:09

Xiongbing Jin