Search code examples
shellmavengitlabdevopsenvironment

How can i declare an environment variable which would stay in a docker container?


I'm trying using

RUN export PATH=$PATH:/ant/apache-ant-1.10.11/bin:/maven/apache-maven-3.8.1/bin

and calling it on a script as

export PATH=$PATH:/ant/apache-ant-1.10.11/bin:/maven/apache-maven-3.8.1/bin

And it just won't work. It seems that the variables are erased after the pipeline for building the image. It just works if i send it maunally from the container itself, but i need it to stay and be like that because it is for devOps and it will use that variable for compiling (i have the 2 techonologies just for testing)

Any hints? I'm in a hurry.

Solution

  • You have to use the env keyword inside your docker file, like follow:

    ENV PATH=$PATH:/ant/apache-ant-1.10.11/bin:/maven/apache-maven-3.8.1/bin
    

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