In my docker-compose.yml I use some .env variables. Just like that:
services:
ms:
image: 'template:latest'
build:
context: .
restart: always
ports:
- '${PORT}:${PORT}'
env_file:
- .env
Docker documentation says, that I have to run docker-compose up command from directory when .env and docker-compose.yml files are present together.
I want to use GitLab CI to deploy my service automatically. This is the part of .gitlab-ci.yml file:
image: docker:latest
services:
- docker:dind
...
run-deploy-prod:
stage: deploy
cache: {}
before_script:
# ssh configuration for alpine linux
script:
# move docker-compose.yml and .env to the location ~/docker_app/app
- ssh $USER_NAME@$HOST_ADDRESS 'docker-compose -f '~/docker_app/app/docker-compose.yml' up --no-build -d'
The question: How can I run docker-compose exactly from the location ~/docker_app/app to load .env variables properly?
I tried to use ssh with -T, -tt and -t options, like:
ssh -T bob@foo "cd ~/docker_app/app && exec \$SHELL && docker-compose up..."
without any success.
Any help would be greatly appreciated.