Skip to content

docker-composer postgres env vars #141

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

Closed
opb opened this issue Apr 1, 2016 · 4 comments
Closed

docker-composer postgres env vars #141

opb opened this issue Apr 1, 2016 · 4 comments

Comments

@opb
Copy link

opb commented Apr 1, 2016

Hi all

I'm trying to bring up a postgres container with docker-compose, while setting custom POSTGRES_* vars.

version: '2'
services:
  db:
    image: postgres
    environment:
      - POSTGRES_USER=pony
      - POSTGRES_PASSWORD=pony
      - POSTGRES_DB=pony
    ports:
      - "5432:5432"
  web:
    image: temp-logger
    volumes:
      - .:/app
    ports:
      - "8888:5000"
    links:
      - db
    depends_on:
      - db

However, when I run docker-compose --verbose up it doesn't look like all the env vars are being passed through:

<snip>
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'cc0aced19d4d2c0bb7205de2886792600e0a9056afa89317b1c41d4d6fa6064c')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'',
 u'Args': [u'postgres'],
 u'Config': {u'AttachStderr': False,
             u'AttachStdin': False,
             u'AttachStdout': False,
             u'Cmd': [u'postgres'],
             u'Domainname': u'',
             u'Entrypoint': [u'/docker-entrypoint.sh'],
             u'Env': [u'affinity:container==cdbf6652d6a65253e798eabdd306d27c25956e59019f0911c47cac9615c08216',
                      u'POSTGRES_PASSWORD=pony',
...
</snip>

It looks like only the password is being set. Indeed, when I connect in from outside the docker ecosystem, I need to use postgres as the username, postgres as the db, and pony works as the password.

Any suggestions as to what I could be doing wrong, or is it a bug?

@mmarzantowicz
Copy link

Please use docker inspect <container name> command to see what environment is set for your database container (including passed variables).

Going back to --verbose output, check what do you have in compose.cli.verbose_proxy.proxy_callable: docker create_container line.

@erwagasore
Copy link

I have the same issue. I tried what you suggested and on both commands I found that env variables are considered still doesn't have effect

This is a portion of docker inspect <container name>

"Config": {
            "Hostname": "3bb47abf0e9e",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "5432/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "POSTGRES_PASSWORD=menui.st",
                "POSTGRES_USER=mnst",
                "POSTGRES_DB=menuist",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=en_US.utf8",
                "PGDATA=/var/lib/postgresql/data"
            ],
            "Cmd": [
                "postgres"
            ],
            "Image": "kiasaki/alpine-postgres:9.5",
            "Volumes": {
                "/var/lib/postgresql/data": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "6c2c6409ac9c27382cbe9f5ae635a5049657ecf8bdc9d9eeb307850620391da0",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "menuist",
                "com.docker.compose.service": "postgres",
                "com.docker.compose.version": "1.7.1"
            }
        }

This is a portion of docker-compose --verbose up

compose.service.create_container: Creating menuist_postgres_1
compose.cli.verbose_proxy.proxy_callable: docker create_container <- (name=u'menuist_postgres_1', image='kiasaki/alpine-postgres:9.5', labels={u'com.docker.compose.service': u'postgres', u'com.docker.compose.project': u'menuist', u'com.docker.compose.config-hash': '6c2c6409ac9c27382cbe9f5ae635a5049657ecf8bdc9d9eeb307850620391da0', u'com.docker.compose.version': u'1.7.1', u'com.docker.compose.oneoff': u'False', u'com.docker.compose.container-number': '1'}, host_config={'NetworkMode': u'menuist_default', 'Links': [], 'PortBindings': {'5432/tcp': [{'HostPort': '5432', 'HostIp': ''}]}, 'Binds': [u'menuist_database:/var/lib/postgresql/data:rw'], 'RestartPolicy': {u'MaximumRetryCount': 0, u'Name': u'always'}, 'LogConfig': {'Type': u'', 'Config': {}}, 'VolumesFrom': []}, environment=[u'POSTGRES_PASSWORD=menui.st', u'POSTGRES_USER=mnst', u'POSTGRES_DB=menuist'], volumes={u'/var/lib/postgresql/data': {}}, detach=True, ports=['5432'], networking_config={u'EndpointsConfig': {u'menuist_default': {u'IPAMConfig': {}, u'Aliases': ['postgres']}}})
compose.parallel.feed_queue: Pending: set([])
compose.cli.verbose_proxy.proxy_callable: docker create_container -> {u'Id': u'3bb47abf0e9ec5623f51f197a79c07458477941092fdc73ad189abfdfb1a9a02',
 u'Warnings': None}

@yosifkit
Copy link
Member

@erwagasore, did you start your postgres container before setting some of the env args? Docker-compose will try hard to keep volumes around when recreating the container, so the entrypoint script from the official image would not apply any of those arguments on an already initialized database.

You are also using kiasaki/alpine-postgres which is not part of this official image repo, but does use a similar entrypoint script.

@yosifkit
Copy link
Member

yosifkit commented Sep 1, 2017

Seems to be similar to #203, so this #203 (comment) might apply as well. Closing old issue.

@yosifkit yosifkit closed this as completed Sep 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants