Piwigo, Docker - "Cannot connect to server"

Hi,

after installation with docker-compose, piwigo can’t connect to the db-container.
Is my docker-compose.yml correct?
Do I need to put the port as well in “Host”?

version: "2"
services:

  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
    volumes:
      - /data_4TB/piwigo/db:/var/lib/mysql

  app:
    image: linuxserver/piwigo
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Paris
    volumes:
      - /data_4TB/piwigo/conf:/config
      - /data_4TB/piwigo/pics:/pictures
    ports:
      - 9988:80
    restart: unless-stopped

give your mysql container a container name and use that as the mysql address

1 Like

same behavior.
do I need some “links”-entry or any other network stuff?

version: "2"
services:

  db:
    image: mysql:latest
    restart: always
    container_name: piwi_db
    environment:
      MYSQL_ROOT_PASSWORD: test
      MYSQL_DATABASE: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
    volumes:
      - /data_4TB/piwigo/db:/var/lib/mysql

  app:
    image: linuxserver/piwigo
    container_name: piwi_app
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Paris
    volumes:
      - /data_4TB/piwigo/conf:/config
      - /data_4TB/piwigo/pics:/pictures
    ports:
      - 9988:80
    restart: unless-stopped

No, compose by default puts them in the same user defined bridge so they can connect to each other via container name as dns name.

Check the container logs for both

mysql

2020-01-11 09:20:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.,
2020-01-11 09:20:19+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql',
2020-01-11 09:20:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.,
2020-01-11 09:20:19+00:00 [Note] [Entrypoint]: Initializing database files,
2020-01-11T09:20:19.630384Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.,
2020-01-11T09:20:19.633262Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 46,
2020-01-11T09:20:30.419385Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.,
2020-01-11 09:20:37+00:00 [Note] [Entrypoint]: Database files initialized,
2020-01-11 09:20:37+00:00 [Note] [Entrypoint]: Starting temporary server,
2020-01-11T09:20:37.705099Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.,
2020-01-11T09:20:37.705399Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 95,
2020-01-11T09:20:38.938566Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.,
2020-01-11T09:20:38.968707Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.,
2020-01-11T09:20:39.026924Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.,
2020-01-11 09:20:39+00:00 [Note] [Entrypoint]: Temporary server started.,
2020-01-11T09:20:39.099112Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock',
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.,
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.,
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.,
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.,
2020-01-11 09:20:47+00:00 [Note] [Entrypoint]: Creating database test,
2020-01-11 09:20:47+00:00 [Note] [Entrypoint]: Creating user test,
2020-01-11 09:20:47+00:00 [Note] [Entrypoint]: Giving user test access to schema test,
,
2020-01-11 09:20:47+00:00 [Note] [Entrypoint]: Stopping temporary server,
2020-01-11T09:20:47.723400Z 14 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.18).,
2020-01-11T09:20:49.787111Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.,
2020-01-11 09:20:50+00:00 [Note] [Entrypoint]: Temporary server stopped,
,
2020-01-11 09:20:50+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.,
,
2020-01-11T09:20:51.367479Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.,
2020-01-11T09:20:51.367770Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 1,
2020-01-11T09:20:52.528490Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.,
2020-01-11T09:20:52.560709Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.,
2020-01-11T09:20:52.631433Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.18'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.,
2020-01-11T09:20:52.856659Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

piwigo

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.,
[s6-init] ensuring user provided files have correct perms...exited 0.,
[fix-attrs.d] applying ownership & permissions fixes...,
[fix-attrs.d] done.,
[cont-init.d] executing container initialization scripts...,
[cont-init.d] 01-envfile: executing... ,
[cont-init.d] 01-envfile: exited 0.,
[cont-init.d] 10-adduser: executing... ,
,
-------------------------------------,
          _         (),
         | |  ___   _    __,
         | | / __| | |  /  \ ,
         | | \__ \ | | | () |,
         |_| |___/ |_|  \__/,
,
,
Brought to you by linuxserver.io,
We gratefully accept donations at:,
https://www.linuxserver.io/donate/,
-------------------------------------,
GID/UID,
-------------------------------------,
,
User uid:    1000,
User gid:    1000,
-------------------------------------,
,
[cont-init.d] 10-adduser: exited 0.,
[cont-init.d] 20-config: executing... ,
[cont-init.d] 20-config: exited 0.,
[cont-init.d] 30-keygen: executing... ,
generating self-signed keys in /config/keys, you can replace these with your own keys if required,
Generating a RSA private key,
...................+++++,
...+++++,
writing new private key to '/config/keys/cert.key',
-----,
[cont-init.d] 30-keygen: exited 0.,
[cont-init.d] 40-install: executing... ,
[cont-init.d] 40-install: exited 0.,
[cont-init.d] 99-custom-files: executing... ,
[custom-init] no custom files found exiting...,
[cont-init.d] 99-custom-files: exited 0.,
[cont-init.d] done.,
[services.d] starting services,
[services.d] done.,

This is what I fill in.
I also tried “piwi_db_1” as container name and “db” as given in the compose-file.

Does anyone have a working example to start from?

I could be wrong here, as i’m not sure what this last screenshot you shared is, but
2020-01-11 09:20:47+00:00 [Note] [Entrypoint]: Creating database test
you created a database named test; we also see this in your compose; in this screenshot though, you’ve told it to connect to a database named user…

i changed it during the setup - I figured I can save sme letters :wink:

lol if you do this, you need to comment on it or show us the change; we’re working off what you’re providing :stuck_out_tongue:

Not sure if you managed to get this working icke-icke. I just stumbled on this post when I was trying Piwigo out in docker.
After running my docker-compose up -d I ran docker-compose ps to get the database container name. I then ran docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' CONTAINER_NAME (where CONTAINER_NAME was replaced by my container name from the ps output).
I used this as the IP address for the Piwigo setup page, with the mariadb port 3306.
e.g. 172.19.0.15:3306

Hope this helps someone else get this setup. I’m happy to share my docker-compose.yml too if needed

IPs change in docker, using the ip address is not a reliable long-term solution. You should either use the container name (docker dns uses container names) or the host ip address and exposed port

Here’s a working YAML I ended up trial/erroring. Be sure to replace both passwords with something stronger and adjusting the data volumes so they match your host directories. You can change port 21212 to something else you prefer as well

version: “3.1”
services:
db:
image: linuxserver/mariadb:latest
restart: always
container_name: piwi_db
environment:
- MYSQL_ROOT_PASSWORD=asdfasdf
- MYSQL_USER=piwigouser
- MYSQL_PASSWORD=asdfasdf
- MYSQL_DATABASE=piwigo
volumes:
- /home/hostcomputeruser/Docker/piwigo/db:/var/lib/mysql
app:
image: linuxserver/piwigo
container_name: piwi_app
environment:
- PUID=1000
- PGID=1000
- TZ=America/New_York
volumes:
- /home/hostcomputeruser/Docker/piwigo/conf:/config
- /home/hostcomputeruser/Docker/piwigo/pics:/pictures
ports:
- 21212:80
restart: unless-stopped

Save the yaml into a docker-compose.yml file and run sudo docker-compose up -d from the same directory. Browse to http://localhost:21212 for the setup and enter:

  • db for Host (service_name defined in the docker-compose file)
  • piwigo for User (MYSQL_USER defined in compose)
  • asdfasdf for Password (MYSQL_PASSWORD)
  • piwigo for Database name (MYSQL_DATABASE)
  • piwigo_ for Database tables prefix (filled in already)

For the Admin config, you can enter what you prefer, but be sure to record/remember it as it is how you will administer Piwigo

Here’s a screenshot of the settings entered:

I would paste another screenshot of the success screen, but I am a new user and cannot post more URLs

Hope this helps someone

i am new to docker. I ran the command:

docker run -d
–name=piwigo
-e PUID=1000
-e PGID=1000
-e TZ=Asia/Hong_Kong
-p 80:80
-v /home/ubuntu/ShareDisk/piwigo:/config
–restart unless-stopped
ghcr.io/linuxserver/piwigo

then, I went to the link set the host as the ip address as the link which directs me to setup page.

but i still got this error.

I don’t know how to use yaml.

by the way, i am running ubuntu 20.04 on my raspberry pi 4.

You need to provide piwigo with a MySQL/MariaDB for piwigo to use.

doesn’t the image come with mySQL?

Nope

i installed mysql and create database with a ‘piwigouser’@‘192.168.1.3’ and opened the connection for any incoming ip address, i changed the binding address to 0.0.0.0

I also ran a python code to make sure ip address of 192.168.1.3 works.

but i still got the error message of “cannot connect to the server”.

your piwigo’s ip isn’t 192.168.1.3; i would suggest you just use 'piwigo'@'%'

sorry, can you explain what i should do now?
I don’t really understand.

oh. i think i know what you mean. thanks.
will try