Docker Community Forums

Share and learn in the Docker community.

Internal variables in Dockerfiles


(Acook) #1

Is there a way to use variables inside of a Dockerfile? I’m not talking about setting system variables for the container, but rather using variables within the Dockerfile itself.

For example, if the version of software I was downloading and installing changed a lot, it would be nice to do something like:

        FROM centos:centos6
        
        SOFTWARE_VERSION=testPackage-1.0
      
        # Install Software and remove RPM
        RUN wget http://server.com/$SOFTWARE_VERSION.rpm
        RUN rpm ivh $SOFTWARE_VERSION.rpm
        RUN rm -rf $SOFWARE_VERSION.rpm

Is something like this possible? Or has it been considered?


(Sven Dowideit) #2

yes :smile:
you want ENV SOFTWARE_VERSION testPackage-1.0

and Docker 1.3.1 - as it processes those when it runs each build step.

see http://docs.docker.com/reference/builder/#env


(Acook) #3

Thank you very much Sven!


(Jrhanco1) #4

I believe ARG is what you’re looking for:
ARG SOFTWARE_VERSION=testPackage-1.0