Answer a question

I have a developer docker image based on ubuntu:14.04 that I use to develop apps for Ubuntu 14.04. I start this image when the machine boots with docker start image-name

My home directory was bind mounted with --volumes when initially created.

To enter the image I have an alias defined in .bash_aliases

alias d_enter="docker exec -ti ub1404-dev /bin/bash"

So to enter the image I just type d_enter

But I often forget to run d_enter after entering a long path and would like d_enter to switch to that internal directory automatically.

The following doesn't work.

docker exec -ti ub1404-dev /bin/bash <(echo ". ~/.bashrc && cd $(pwd)")

Is there another way I could achieve the desired result?

For example, if my current working directory is: /home/matt/dev/somepath/blabla

And I type d_enter, my current working directory currently becomes: /home/matt what I want to do for current directory after exec is be /home/matt/dev/somepath/blabla

Answers

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/

Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐