0

I know that you can install a specific version of a yum package using the <package name>-<version> like this:

yum install docker-engine-1.8.2

But I'm trying to customize this using an environment variable such that if it's set, we use that version, else we use the latest. Is there some sort of pseudo-version number like "latest" that would work?

yum install docker-engine-${DOCKER_VERSION:-latest}

Obviously, using "latest" won't work, but is there something equivalent? Normally I would just use an if conditional here, but this is actually a line in a Dockerfile not a shell script, so it's rather limited in what it can do.

2

I found that ${VAR:+...} will let you use "..." if the var is set, otherwise it will be empty. So using that with ${VAR:-...} gives me what I'm looking for:

 yum install docker${DOCKER_VERSION:+-}${DOCKER_VERSION}

so if DOCKER_VERSION is set it to "1.8.2" will look like:

yum install docker-1.8.2

And if it's not set, it will look like

yum install docker

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.