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\}/.

  • Flanneld not working in Kubernetes Multinode Example
  • When using docker-compose to fire up containers how do I programatically get their ips?
  • Scaling a two-tier MEAN application with Docker on AWS
  • Unable to connect to containers of a swarm in docker-in-docker
  • Spring Cloud Eureka Client
  • How to recreate Docker container?
  • I find the inconsistent variable handling very frustrating; How am I supposed to specify this directory for use?

  • Difference between “expose” and “publish” in docker
  • Dockerfile image path contains invalid charector
  • docker automatically commit and push
  • Failed Installation of Docker plugin for Intellij Idea CE 2016.1 due to <required plugin “org.jetbrains.plugins.remote-run” not installed.>
  • Unable to dockerize a nodeapp
  • Docker: understanding ENTRYPOINT and CMD instructions
  • One Solution collect form web for “How to use env var in WORKDIR stanza?”

    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.