# SQLSTATE\[HY000\] \[2002\] Connection timed out

**URL:** <https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275>\
**Category:** Installation Issues\
**Created:** [January 4, 2023, 12:58am UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275 "2023-01-04T00:58:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![divine](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/divine/32/1637_2.png) [@divine](https://community.passbolt.com/u/divine)\
**Post date:** [January 4, 2023, 12:58am UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/1 "2023-01-04T00:58:38Z")

</div>

Hello

I use Ubuntu 22.04.1 LTS with docker

The only thing I set in the docker-compose-ce.yaml is:  
`DATASOURCES_DEFAULT_HOST: "172.16.0.18"`  
(i wanted to make sure that i change as little as possible and just get a runnable instance)

```auto
Version: '3.9'
services:
  db:
    image: mariadb:10.3
    restart: unless-stopped
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "true"
      MYSQL_DATABASE: "passbolt"
      MYSQL_USER: "passbolt"
      MYSQL_PASSWORD: "P4ssb0lt"
    volumes:
      - database_volume:/var/lib/mysql

  passbolt:
    image: passbolt/passbolt:latest-ce
    #Alternatively you can use rootless:
    #image: passbolt/passbolt:latest-ce-non-root
    restart: unless-stopped
    depends_on:
      - db
    environment:
      APP_FULL_BASE_URL: https://passbolt.local
      DATASOURCES_DEFAULT_HOST: "172.16.0.18"
      DATASOURCES_DEFAULT_USERNAME: "passbolt"
      DATASOURCES_DEFAULT_PASSWORD: "P4ssb0lt"
      DATASOURCES_DEFAULT_DATABASE: "passbolt"
    volumes:
      - gpg_volume:/etc/passbolt/gpg
      - jwt_volume:/etc/passbolt/jwt
    command: ["/usr/bin/wait-for.sh", "-t", "0", "db:3306", "--", "/docker-entrypoint.sh"]
    ports:
      - 80:80
      - 443:443
    #Alternatively for non-root images:
    # - 8080:80
    # - 4443:433

volumes:
  database_volume:
  gpg_volume:
  jwt_volume:

```

docker ps:

```auto
~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85a38be9199b passbolt/passbolt:latest-ce "/usr/bin/wait-for.s…" 2 minutes ago Up 2 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp root_passbolt_1
7b8efa029e21 mariadb:10.3 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp root_db_1

```

```auto
~# docker logs 85a38be9199b
wait-for.sh: waiting for db:3306 without a timeout
wait-for.sh: db:3306 is available after 0 seconds
gpg: keybox '/var/lib/passbolt/.gnupg/pubring.kbx' created
gpg: /var/lib/passbolt/.gnupg/trustdb.gpg: trustdb created
gpg: key 64944D38F7B1A439: public key "Passbolt default user <passbolt@yourdomain.com>" imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: key 64944D38F7B1A439: "Passbolt default user <passbolt@yourdomain.com>" not changed
gpg: key 64944D38F7B1A439: secret key imported
gpg: Total number processed: 1
gpg: unchanged: 1
gpg: secret keys read: 1
gpg: secret keys imported: 1
Generating a RSA private key
..............................++++
.....................++++
writing new private key to '/etc/ssl/certs/certificate.key'
-----
Installing passbolt

     ______  ____
    / __\____  _________ / /_ ____ / / /_
   / /_/ / __`/___ / ___/__ \/ __\/ /__ /
  / ____/ /_/ (__ |__ ) /_/ / /_/ / / /
 /_/ \ __,_/____ / ____/_.___ /\ ____/_/\__ /

 Open source password manager for teams
-------------------------------------------------------------------------------
Running baseline checks, please wait...
Notice Error: Undefined index: message
In [/usr/share/php/passbolt/src/Utility/Healthchecks/DatabaseHealthchecks.php, line 72]

2023-01-04 00:37:23 notice: Notice (8): Undefined index: message in [/usr/share/php/passbolt/src/Utility/Healthchecks/DatabaseHealthchecks.php, line 72]
Exception: Connection to Mysql could not be established: SQLSTATE[HY000] [2002] Connection timed out
In [/usr/share/php/passbolt/vendor/cakephp/cakephp/src/Database/Driver.php, line 133]

Running migrations

     ______  ____
    / __\____  _________ / /_ ____ / / /_
   / /_/ / __`/___ / ___/__ \/ __\/ /__ /
  / ____/ /_/ (__ |__ ) /_/ / /_/ / / /
 /_/ \ __,_/____ / ____/_.___ /\ ____/_/\__ /

 Open source password manager for teams
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
 Running migration scripts.
-------------------------------------------------------------------------------
using migration paths
 - /etc/passbolt/Migrations
using seed paths
Exception: There was a problem connecting to the database: SQLSTATE[HY000] [2002] Connection timed out
In [/usr/share/php/passbolt/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php, line 96]

wait-for.sh: waiting for db:3306 without a timeout
wait-for.sh: db:3306 is available after 0 seconds
gpg: key 64944D38F7B1A439: "Passbolt default user <passbolt@yourdomain.com>" not changed
gpg: Total number processed: 1
gpg: unchanged: 1
gpg: key 64944D38F7B1A439: "Passbolt default user <passbolt@yourdomain.com>" not changed
gpg: key 64944D38F7B1A439: secret key imported
gpg: Total number processed: 1
gpg: unchanged: 1
gpg: secret keys read: 1
gpg: secret keys unchanged: 1
Installing passbolt

```

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![garrett](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/garrett/32/545_2.png) [@garrett](https://community.passbolt.com/u/garrett)\
**Post date:** [January 4, 2023, 2:19am UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/2 "2023-01-04T02:19:35Z")

</div>

> [@divine](#):
>
> The only thing I set in the docker-compose-ce.yaml is:  
> `DATASOURCES_DEFAULT_HOST: "172.16.0.18"`  
> (i wanted to make sure that i change as little as possible and just get a runnable instance)

Hi @divine Welcome to the forum!

How does it work with `db` instead of the ip address?

---

<div class="post-metadata">

**Author:** ![divine](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/divine/32/1637_2.png) [@divine](https://community.passbolt.com/u/divine)\
**Post date:** [January 4, 2023, 8:51am UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/3 "2023-01-04T08:51:04Z")

</div>

Thanks garret!

I made a  
`docker inspect`  
and found out, that the IP of the DB is 172.18.0.2

I’ve added this IP to: `DATASOURCES_DEFAULT_HOST` variable.

I’ve checked the logs and still:  
`Exception: Connection to Mysql could not be established: SQLSTATE[HY000] [1045] Access denied for user 'passbolt'@'172.18.0.3' (using password: YES)`

I wasn’t sure, if you meant, putting the term “db” in this field, so a tried this as well. Unfortunately, it didn’t work

Why does he look for 172.18.0.3 instead of 172.18.02?  
172.18.0.3 seems to be the IP of the passbolt contianer… Hmm…

Here’s a docker logs of the DB:  
2023-01-04 9:00:14 205 [Warning] Access denied for user ‘passbolt’@‘172.18.0.3’ (using password: YES)

It looks for me like the connection works, just a problem with the DB?  
I’ve used the standard docker-compose-ce.yaml  
Any idea?

---

<div class="post-metadata">

**Author:** ![garrett](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/garrett/32/545_2.png) [@garrett](https://community.passbolt.com/u/garrett)\
**Post date:** [January 4, 2023, 1:33pm UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/4 "2023-01-04T13:33:21Z")

</div>

The passbolt user is coming from `172.18.0.3` so the reference is from the point of view of the db referencing the authorization identifier of `user@host`.

Step 5 here [Passbolt Help | Docker passbolt installation](https://help.passbolt.com/hosting/install/ce/docker.html)

It creates an admin user. The docker compose command should not be run without the `exec` portion of the command shown. If you did this step already but with the wrong ip address, it might be best to start over.

---

<div class="post-metadata">

**Author:** ![divine](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/divine/32/1637_2.png) [@divine](https://community.passbolt.com/u/divine)\
**Post date:** [January 4, 2023, 5:31pm UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/5 "2023-01-04T17:31:58Z")

</div>

Thanks a lot for your help, makes sense!

I’m sorry to ask, but:

> If you did this step already but with the wrong ip address

Do I have to specify the IP also within the docker-compose command, or do you meant within the docker-compose-ce.yaml ?

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/passbolt/original/2X/5/5a595c2510f02d2a86e71482b8dff88e8dccef6b.png)

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/passbolt/original/2X/f/ff80656f8a3406de036fd6dff9aac017b35accab.png)

The command in step 5 looks like this:  
`docker-compose -f docker-compose-ce.yaml exec passbolt su -m -c "/usr/share/php/passbolt/bin/cake passbolt register_user -u XXXXXXX@gmail.com -f predix -l predix -r admin" -s /bin/sh www-data`

Is this OK?

How did I start over? → I stoped and delted the containers. Is this enough?

---

<div class="post-metadata">

**Author:** ![garrett](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/garrett/32/545_2.png) [@garrett](https://community.passbolt.com/u/garrett)\
**Post date:** [January 4, 2023, 8:08pm UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/6 "2023-01-04T20:08:50Z")

</div>

The yaml file should have `db` instead of the ip address, and it will automatically know which address the `db` container has.

If you run the command as you show, without the `-d` and with the other `exec` command, you will see if there are any errors.

[Edit: start containers first!]  
If everything is good you will get a link. Open a second terminal if needed until you have finished setup.

---

<div class="post-metadata">

**Author:** ![divine](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/divine/32/1637_2.png) [@divine](https://community.passbolt.com/u/divine)\
**Post date:** [January 4, 2023, 9:22pm UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/7 "2023-01-04T21:22:57Z")

</div>

I’ve stopped and removed the containers and tried again; sadly, no link, still the same error 😪:

My yaml looks like that:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/passbolt/original/2X/d/d8d0f16c494f987104384e15597ed32cf7104e72.png)

I also treid:  
` DATASOURCES_DEFAULT_HOST: db`  
instead of:  
` DATASOURCES_DEFAULT_HOST: "db"`

---

<div class="post-metadata">

**Author:** ![garrett](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/garrett/32/545_2.png) [@garrett](https://community.passbolt.com/u/garrett)\
**Post date:** [January 4, 2023, 10:49pm UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/8 "2023-01-04T22:49:16Z")

</div>

@diego Do you have any insight on this error?

---

<div class="post-metadata">

**Author:** ![divine](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.passbolt.com/divine/32/1637_2.png) [@divine](https://community.passbolt.com/u/divine)\
**Post date:** [January 5, 2023, 2:16am UTC](https://community.passbolt.com/t/sqlstate-hy000-2002-connection-timed-out/6275/9 "2023-01-05T02:16:53Z")

</div>

I had to do a:  
`docker system prune --volumes`  
This deleted everything docker related: [Prune unused Docker objects | Docker Documentation](https://docs.docker.com/config/pruning/)  
The next try worked, I got the URL.
