-
Notifications
You must be signed in to change notification settings - Fork 1.2k
User and database not created with docker-compose #537
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
Comments
I can't reproduce any issue with your compose file version: '3'
services:
postgresql:
image: postgres:alpine
environment:
POSTGRES_DB: iotplatform
POSTGRES_USER: iotplatform
POSTGRES_PASSWORD: iotplatform $ docker-compose up -d
Creating network "postgres-537_default" with the default driver
Creating postgres-537_postgresql_1 ... done
$ docker exec -it postgres-537_postgresql_1 psql -Uiotplatform
psql (11.1)
Type "help" for help.
iotplatform=# |
@wglambert After running Today I learned: there are harder resets than |
I am experiencing the same issue. How did you solve? |
@joaosgreccia |
recreating the volume solved the problem for me. found the solution here: https://stackoverflow.com/questions/48629799/postgres-image-is-not-creating-database/54200233#54200233 |
In particular, if your volume is still attached to your container and you want to hard reset it, use: $ docker-compose stop
$ docker-compose rm (fuller discussion here: docker/compose#2127 (comment)) On the other hand, if your volume was orphaned from your container somehow (which is what happened to me), you can use $ docker volume ls to list out the the current volumes on your system (and the orphaned one will show up here, if it exists), then you can use: $ docker volume prune to remove all the volumes that aren't currently being referenced by a container (i.e. your orphaned volume). |
Still have the same problem. Nothing from above helped :( |
In same situation. I clear volume, run compose file without volume. But still my db name is "postgres".
root@da56af4f3da7:/# echo $POSTGRES_USER
root@da56af4f3da7:/# psql -Ubeaver
|
I had same problem and solution above from @foucdeg worked for me You should put a note in the docs about this It's too easy to Once you know why it's obvious but it's frustrating for a while before that |
@anentropic see @yosifkit 's linked issue, it's probably a better place to suggest documentation. |
Pretty sure docker-compose will re-up the container if you change any values in the compose file So I think the issue is around the persistent volume, i.e. change in env vars has no effect on the existing db. ...right, this is what's described in #203 as you say The behaviour makes sense when you understand how it works, which is why I think a note about this specific case in the docs would be helpful. |
i have same problem |
@amirmahdisaadati I had a similar problem; this is what I ended up doing (slowly tacking on flags until it worked)
|
Stop containers and remove the volumes created by up. $ docker-compose down --volumes Stop containers and remove containers, networks, volumes, and images created by up. $ docker-compose down --rmi all --volumes
|
Please make sure there is no other |
I had the same problem. My solution:
Create /db_init/Dockerfile:
In Docker-compose I set for postgre service:
But I don't know how set env from .env in /db_init/Dockerfile |
I had the same issue.
Here is my docker-compose.yml
|
I have a problem, because I do the docker-compose up with postgres, everything works normally, but when I go to my postgres, in psql and give the command \dt, in my database, the message appears: 'Did not find any relations.'. Does anyone know what can it be? Here is my docker-compose
When I run on localhost, without docker-compose, the database is populated, so I believe the problem is in my docker-compose |
I had the same problem. My solution: |
(Copy of my SO question)
The docs explain that you can make the image create a user and database on creation, using environment variables.
I can't seem to make that work using docker-compose:
and here's what I run:
When I run
docker-compose exec postgresql env
, I see the environment variables as configured.The logs don't say anything particular:
Without docker-compose, the variables work fine:
What am I missing?
The text was updated successfully, but these errors were encountered: