HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Docker compose volume syntax valid for Windows and Linux

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
dockerandsyntaxvalidcomposeforwindowslinuxvolume

Problem

We have developers working on an app using both Windows and Linux. The application is built within a Docker container, and ships a docker-compose specification for the build environment.

The local directory is mounted as a volume:

volumes:
      - ${PWD}:/tmp


however this doesn't work in Windows because $PWD is not defined.

My question is:

Can we have a single docker-compose.yml to satisfy both the Windows and Linux developers?

The obvious way to do this seems to me to have two docker-compose files, one for each OS.

Solution

Yes. Just use ./ for you current directory that the Docker-compose file is in. Your "working directory" for the compose file is just "./". If you are trying to set a directory below that it would look something like:
volumes:

./DirectoryIWantToTarget:/tmp


There's an example of this in the Docker-Compose documentation here. This approach makes the solution cross-platform as well.

Code Snippets

volumes:

./DirectoryIWantToTarget:/tmp

Context

StackExchange DevOps Q#9002, answer score: 10

Revisions (0)

No revisions yet.