2018-07-17

Run docker container with access to the current working directory

Containers are an amazing technology and Docker makes it fast and easy to get one up and running, so you can make your local system look and behave like it were a different OS/distro/version. This can be extremely useful for testing how code behaves in different environments.

Sometimes, though, one does not have time to write a Dockerfile. For ad-hoc testing one sometimes would like to just get a bash prompt in a container. This can be done like so:

$ docker run -i -t opensuse bash

But this has the disadvantage (or advantage, depending on point of view) that the local filesystem is inaccessible. Docker gives the container a completely fresh filesystem to work in. What if we just want to give the container read/write access to the current working directory?

The magic incantation for that is:

docker run -v $(pwd):$(pwd) -w $(pwd) -i -t opensuse bash

Since that's unfit for storage in failing human memory, I'll put it here :-)

No comments:

Post a Comment