How can I set the current working directory for docker exec with an internal bash shell?
From API 1.35+ you can use the -w
(--workdir
) option:
docker exec -w /my/dir container_name command
https://docs.docker.com/engine/reference/commandline/exec/
You can achieve it with:
docker exec -it containerName sh -c "cd /var/www && /bin/bash"
When building an image, one can specify the WORKDIR variable in Dockerfile
:
WORKDIR /var/www/html