-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Problem setting environment variables through docker-compose #203
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Comments
I suspect this is happening because you have a previous image of this in your docker where you ran |
Hi, it did not work :( I removed all the images in my local machine and regardless still not working. Below the log output when I run
has something to do this line? at the moment and as workaround I create the DB / user / pass manually. |
I still don't get it but I am using the following version: '2'
services:
postgres:
image: postgres:9.3
ports:
- "5432:5432"
environment:
- POSTGRES_USER=test
- POSTGRES_PASSWORD=test
- POSTGRES_DB=test_db
volumes:
- ./data/postgres:/var/lib/postgresql/data |
your script works like a charm! Still I do not get exactly what I was doing wrong (maybe it was the version:'2' or nest the services under 'services' tag..), but it does not mind, I move forward. Thanks for your help! |
Had the exact same problem. Removed all images and deleted the data directory as @mrafayaleem suggested - works! |
Yeah, the problem is not the existing images on your host, but it stems from the volume (or bind mount directory) being already initialized after your first start. The postgres user, and database creation only happens on the first start (ie, Here is an example flow
If you do not declare a volume mount point, then the An example without a bind mounted volume:
You can see what volumes you have on your host by doing a If you want to clean up all local volumes that are not attached to containers (WARNING this could delete important data 😲): Also, in case it is not obvious, do not delete your postres data directory or volume if you have important data stored there. 😱 |
I do not know for sure if it was the root cause, but the syntax used to specify the environment:
- POSTGRES_DB:test_db You can either specify it as a hash (no environment:
POSTGRES_DB:test_db Or as an array, environment:
- POSTGRES_DB=test_db |
This issue is still not resolved for me. I tried removing the images after shutdown with
I still get the following output
|
@doc-phily, the output of your logs look correct. The On a side note, |
There may be an older instance of the image. Be sure to run docker-compose build. |
WORKED! =) |
anybody know a convenient way to have postgres run a script on startup even if the data directory is not empty? i have an idempotent migration script i just want to run any time the container starts. |
@escalonn Did you find a way to do this ? |
@thomascrha nope. i don't think it exists so when i get back to that project i plan to just psql it from another container. |
FYI, was helping a teammate with this issue today. It turns out they had a local installation of PostgreSQL running, and that was causing the issue. Once we stopped the (brew packaged) service with |
For me adding |
|
I have problems to create a custom DB in docker-compose using the environment variables and postgres docker image.
having this
docker.compose.yml
file and runningdocker-compose up -d
the container created does not contain the
test_db
databaseBut if I run the following command:
docker run -e POSTGRES_DB=test_db --name postgres-test -d -p 5432:5432 postgres
the created container DO have the
test_db
I was reading the following links and everything looks good.
https://hub.docker.com/_/postgres/
https://docs.docker.com/engine/reference/run/#/env-environment-variables
https://docs.docker.com/compose/environment-variables/
Sure I am missing something because it should be straightforward. But what?
thank for your time and help!
The text was updated successfully, but these errors were encountered: