New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
My docker build image deployed from Github Packages on portainer runs but fails to connect to the database
Post Body

Currently I have a dockerized Django API on GitHub. The

This is is the docker-compose.yml file:-

version: "3.9"
services:
nginx:
build: ./nginx
ports:
- ${PORT}:80
volumes:
- static-data:/vol/static
depends_on:
- web
restart: "on-failure"
redis:
image: redis:latest
ports:
- 6379:6379
volumes:
- ./config/redis.conf:/redis.conf
command: ["redis-server", "/redis.conf"]
restart: "on-failure"
db:
image: postgres:13
volumes:
- ./data/db:/var/lib/postgresql/data
env_file:
- database.env
restart: always
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
container_name: vidhya_io_api
volumes:
- .:/shuddhi
ports:
- 8000:8000
expose:
- 8000
depends_on:
- db
- redis
restart: "on-failure"
volumes:
database-data: # named volumes can be managed easier using docker-compose
static-data:

This is what I did:-

  1. I just added the registry and added the authentication PAT for GitHub and the registry added successfully
  2. Then I added a container with a link to the package on GitHub that gets automatically built and updated on every push to the master branch
  3. I then added all the environment variables needed to the necessary fields in the Advanced Container Settings console down below and clicked on Deploy the container.
  4. The container gets deployed but when I go to the image and see the log, it says this:-

2022-01-16T15:01:00.069346425Z /usr/local/lib/python3.8/site-packages/environ/environ.py:637:

2022-01-16T15:01:01.953207056Z Waiting for database...

2022-01-16T15:01:04.088619165Z Database unavailable, waiting 1 second...

2022-01-16T15:01:07.031431230Z Database unavailable, waiting 1 second...

2022-01-16T15:01:10.775804216Z Database unavailable, waiting 1 second...

2022-01-16T15:01:14.004302157Z Database unavailable, waiting 1 second...

2022-01-16T15:01:16.946857625Z Database unavailable, waiting 1 second...

I have a script that checks for whether the database is initialized or not and just waits and checks periodically before running the app. And it is unable to access the database. I'm not sure what's going wrong here. When I run the same locally with the same env variables, it's able to access the database.

I'm not sure if you would need to see my Django code to be able to comment, but I don't think it matters since I have this running both locally and on Heroku perfectly fine with the same variables filled in the env vars.

Btw I have a variable called DATABASE_URL that contains a remotely located postgres database and contains the auth stuff right in the URL that I have added as an env var in the container.

I think something obvious is not getting initialized on portainer. I just don't have enough of expertise to figure out what it is.

If someone can offer a hint that would be great.

Thanks!

Author
Account Strength
100%
Account Age
3 years
Verified Email
Yes
Verified Flair
Yes
Total Karma
4,486
Link Karma
2,532
Comment Karma
1,051
Profile updated: 1 day ago
Posts updated: 1 week ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago