-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
docker-compose database connection error #65
Comments
Are you using docker-compose, if so could you post your config? |
Sure thing, here's the snippet
|
It seems to have problems parsing the MYSQL_URL environment variable. I'm not entirely sure why this happends, maybe the quotes around the MYSQL_URL value trips it up, could you try to delete them? Like so: - "/etc/localtime:/etc/localtime:ro"
environment:
- MYSQL_URL: "$PHOTOVIEW_MYSQL_USER:$PHOTOVIEW_MYSQL_PASSWORD@tcp($DB_HOST)/photoview"
+ MYSQL_URL: $PHOTOVIEW_MYSQL_USER:$PHOTOVIEW_MYSQL_PASSWORD@tcp($DB_HOST)/photoview
API_LISTEN_IP: photoview |
I did try that and it behaves the same. |
I read here that someone had similar problems because of whitespaces, could you try to format the config like so (again just a guess): - "/etc/localtime:/etc/localtime:ro"
environment:
- MYSQL_URL: "$PHOTOVIEW_MYSQL_USER:$PHOTOVIEW_MYSQL_PASSWORD@tcp($DB_HOST)/photoview"
- API_LISTEN_IP: photoview
- API_LISTEN_PORT: 80
- PHOTO_CACHE: /app/cache
- PUBLIC_ENDPOINT: "https://photoview.$DOMAINNAME/"
+ MYSQL_URL=$PHOTOVIEW_MYSQL_USER:$PHOTOVIEW_MYSQL_PASSWORD@tcp($DB_HOST)/photoview
+ API_LISTEN_IP=photoview
+ API_LISTEN_PORT=80
+ PHOTO_CACHE=/app/cache
+ PUBLIC_ENDPOINT=https://photoview.$DOMAINNAME/
labels: Hope it helps |
Same thing. I have a few other containers that use mysql databases and they are all configured with environment variables like below and work great. Not sure how difficult that would be to implement.
|
I would have to look further into that |
Cool, let me know what you figure out. I've tried just about every format I can think of for the environment variable to get it to work and I end up with the same error every time. |
So Photoprism is using pretty much the same format as you are for database connection and I am able to spin up that container using the example docker-compose.yml they have provided. I'm still unable to get yours to work, maybe something in there will clarify what the issue is, but I'm not savvy enough to dig into the code unfortunately. I have my database set up like this, which differs from their example, but it still works.
|
I just looked at the way Photoprism does it, and it seems that they use a different library for connecting to the database, which makes it hard to compare. I found this article describing the use of variables in docker compose: It mentions the command |
Here's the output of that command with sensitive info removed.
|
I just tried to reproduce the error, but everything worked as expected. version: "3"
services:
db:
image: mariadb
restart: always
environment:
- MYSQL_DATABASE=photoview
- MYSQL_USER=$PHOTOVIEW_MYSQL_USER
- MYSQL_PASSWORD=$PHOTOVIEW_MYSQL_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD=1
volumes:
- db_data:/var/lib/mysql
photoview:
image: viktorstrate/photoview:latest
restart: always
ports:
- "8000:80"
depends_on:
- db
environment:
# - MYSQL_URL=photoview:photo-secret@tcp(db)/photoview
- MYSQL_URL=$PHOTOVIEW_MYSQL_USER:$PHOTOVIEW_MYSQL_PASSWORD@tcp($DB_HOST)/photoview
- API_LISTEN_IP=photoview
- API_LISTEN_PORT=80
- PHOTO_CACHE=/app/cache
# Change This: The publicly exposed url
# For example if the server is available from the domain example.com,
# change this value to http://example.com/
- PUBLIC_ENDPOINT=http://localhost:8000/
volumes:
- api_cache:/app/cache
# Change this to the directory where your photos are located on your server.
# If the photos are located at `/home/user/photos`, then change this value
# to the following: `/home/user/photos:/photos:ro`.
# You can mount multiple paths, if your photos are spread across multiple directories.
- ./photos_path:/photos:ro
volumes:
db_data:
api_cache: And exported the following environment variables: export PHOTOVIEW_MYSQL_USER=photoview
export PHOTOVIEW_MYSQL_PASSWORD=photo-secret
export DB_HOST=db:3306 You said that you've removed sensetive information, which is understandable, but does your real db username, password or host contain a colon symbol |
So I think I figured it out. It wasn't any characters in the string, it turns out it was the database container that was causing the problem. I switched from |
I'm getting the following error when starting the container. I am using the hostname of the database because it doesn't use a static IP. I've tried different formatting unsuccessfully .
The text was updated successfully, but these errors were encountered: