0

Take the following simplified example:

services:
  app:
    image: alpine
    env_file: config.env
    entrypoint:
      - /bin/sh
      - -c
      - 'echo "Var is: $$MY_VAR"'

I have config.env locally with my local dev settings, and a config.env on the server with production settings.

When I use docker-compose -H user@example.com up --build -d, it uses my local config.env instead of the one on the server. I'd rather not store environment-specific configuration in my repository, however the methods recommended in the docker documentation all involve making separate .yml files or .env files on the same machine on which you're using docker-compose.

So, my question is, how can I store configuration on my server, and use docker-compose on my dev machine to deploy? Or am I better off just uploading the repo to the server and running docker-compose there so I can use the remote env file?

Ben Davis
  • 250
  • 1
  • 4
  • 16

1 Answers1

0

I eventually went with creating my own deploy script that copies the docker-compose files to the server and using an environment file on the server:

scp docker-compose.yml $USER@$HOST:/tmp/
deploy_cmd="export \$(grep -v '#.*' \"$REMOTE_ENV_FILE\" | xargs)";
deploy_cmd="$deploy_cmd && docker stack deploy -c /tmp/docker-compose.yml my-project";
echo "Deploying to $USER@$HOST"
ssh -qA "$USER@$HOST" "$deploy_cmd" || return 1;
Ben Davis
  • 250
  • 1
  • 4
  • 16