I’m encountering a problem and I’m not sure how to solve it. I have a docker compose file that mounts a volume from the host to the container. When running docker-compose up locally, the path on the host will always be the same. However, when running docker-compose up from the Continuous Integration (CI) server, the path is different.
For example, the docker-compose has the following
volumes:
- ${HOME}/directory:/root/directory
I want to have the following when docker-compose is run on the CI server
Why not just use your own environment var and set it appropriately on both systems? That is sort of the point of env vars.
Alternatively, just use - “./mydir:/root/directory” and create a soft link to ./mydir from ${HOME}/mydir on one machine and from ${ANOTHER_VARIABLE}/directory on the other.
First, there may be multiple people running docker-compose locally.
Second, an environment variable requires system configuration. Since docker-compose doesn’t currently support advanced variable substitution, it’s not ideal since we would need to ensure that every local execution has this env var defined.
Third, a symbolic link requires every host to have it exist on the system. If the symlink isn’t on the system, the containers started from docker-compose won’t have the required volumes.
The solution I came up with has less chances of failing due to the host being “misconfigured”.