ThorSummoner
ThorSummoner

Reputation: 18159

How to use env var in WORKDIR stanza?

I have a pretty slim Dockerfile so far:

FROM ubuntu:trusty

ENV MYPACKAGE_VERSION 0.1.2
ADD mypackage-${MYPACKAGE_VERSION}.tar.gz /root/
WORKDIR /root/mypackage-${MYPACKAGE_VERSION}/

The .tar.gz gets properly added to the docker file, (it is automatically extracted which is frustrating as that may not be desirable at all times). so on the image the path /root/mypackage-0.1.2/ exists and contains the content I want to work with, however the WORKDIR stanza cd's into the literal path /root/mypackage-${MYPACKAGE_VERSION}, escaped as /root/fifechan-\$\{FIFECHAN_VERSION\}/.

I find the inconsistent variable handling very frustrating; How am I supposed to specify this directory for use?

Upvotes: 0

Views: 366

Answers (1)

Matt Harrison
Matt Harrison

Reputation: 13587

See Github issue here: https://github.com/docker/docker/issues/2637. The issue suggests this has now been fixed. Are you using the latest version?

You can also override the WORKDIR in the Dockerfile when calling docker run:

docker run -w=/root/mypackage-0.13

Upvotes: 1

Related Questions