Why can't I cd to a directory with docker run?

Solution 1:

You can use -w option to change your working directory.

docker run

  -w, --workdir=""           Working directory inside the container

So, in your case, you'd run:

sudo docker run -w /local/deploy/decomposer -P ubuntu/decomposer ./decomposer-4-15-2014

Solution 2:

Pass your command as an argument to /bin/sh like this:

sudo docker run -P ubuntu/decomposer /bin/sh -c 'cd /local/deploy/decomposer; ./decomposer-4-15-2014'

Solution 3:

Use WORKDIR in your Dockerfile to set the working directory. Then you can run your command with EXEC.

Tags:

Docker