Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables are not set when using docker-compose through ssh #4282

Closed
m-a-d-e opened this issue Dec 29, 2016 · 4 comments
Closed

Comments

@m-a-d-e
Copy link

m-a-d-e commented Dec 29, 2016

Hello,

Given docker-compose 1.9.0 and the following docker-compose.yml:

version: '2'
services:
kafka:
image: wurstmeister/kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: ${HOSTNAME}

When I execute the following command:

ssh foo@bar.mydomain.com "docker-compose up -d

Then the hostname environment variable is not recognized. I get the following message:

The HOSTNAME variable is not set. Defaulting to a blank string.

If I execute the same command on the host "bar" with the user "foo" I don't get the error. Same if I first connect with ssh, and then execute the command.
This is a major issue for us. This workflow happens in our CI.

The only workaround we found is to write the following script:

#!/bin/bash
export HOSTNAME=${HOSTNAME}
docker-compose up -d

And execute it through ssh.. Which is not handsome..

@shin-
Copy link

shin- commented Jan 5, 2017

Well, doesn't that happen because when executing the command through ssh directly, you're not actually opening a shell? Meaning that some environment variables like $HOSTNAME will not be set?

Looks like your issue is with UNIX and/or SSH - I don't see anything that can be done about this at the Compose level.

@m-a-d-e
Copy link
Author

m-a-d-e commented Jan 6, 2017

That's what I was thinking. But the following command workaround works.. Which means that the variable HOSTNAME is correctly set during the ssh session. So I don't know why compose do not recognize it... That's weird.

@shin-
Copy link

shin- commented Jan 7, 2017

I found this which seems relevant. bash does not export $HOSTNAME by default, which explains why it's not being seen by docker-compose.

I was able to reproduce locally in my Ubuntu 16.04 environment so I can confirm this has nothing to do with SSH, either.

@shin- shin- closed this as completed Jan 24, 2017
@vikramvi
Copy link

@shin- @m-a-d-e How to fix this on Ubuntu, please clarify ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants