Nextcloud-docker-dev connect sql client to database

I am using the docker nextcloud-docker-dev to learn about nextcloud and am trying to connect to the database to watch changes I am testing. However, I am not sure what IP address to use to connect to the database.

When inspecting the database container I see:

		"NetworkMode": "master_default",
		"PortBindings": {
			"3306/tcp": [
				{
					"HostIp": "127.0.0.1",
					"HostPort": "8212"
				}
			]
		},

I tried mysql -h 127.0.0.1 -u nextcloud but that give the error ERROR 2002 (HY000): Can't connect to server on '127.0.0.1' (115).

I also tried ::1 because that is what the url (nextcloud.local) the web interface come back to when doing a ping on it.

I think the docker database container is built with this part of the compose file.

  database-mariadb-primary:
    image: docker.io/bitnami/mariadb:10.6
    ports:
      - "${IP_BIND:-127.0.0.1}:3306:3306"
    volumes:
      - 'mariadb_primary_data:/bitnami/mariadb'
    environment:
      - MARIADB_REPLICATION_MODE=master
...

I am using docker desktop on Linux and for the database container it has a port of 8212:3306 and links to http://127.0.0.1:8212/ that give me a bunch of gibberish in the browser.

Any ideas of what ip address and port I could use to connect to the database?

Thank you.

Well…

First welcome to the forum and NC development.

The direct answer ist: Use port 8212 in that case. The SQL server listens on one port by default 3306. This is where the client connects by default. For whatever reason, your setup has 8212 configured as routed port. So if you connect on 127.0.0.1:8212 on your host this gets (by docker) redirected to the container port 3306.

However, there is a script in the scripts folder that allows you to dig into the DB directly. This might be more convenient as you have to think less about stuff.

Chris

1 Like

Alternatively a phpmyadmin service is also included in the docker compose file, which might be enough to dig into the database

Thank you christianlupus. After using the correct port I was able to connect without any issues.

I looked at the script but I am not sure how to use it. It would be nice if there was some examples some place. It says to pass in MySQL Params. Not sure what that is.

Hi SysKeeper. Thanks for the suggestion.

I am not sure how to start phpmyadmin. I am use to using compose files and starting and stopping from the command line but in this project I installed docker.desktop.

I changed the docker compose file and added phpmyadmin as a dependency of nextcloud but stopping and starting in docker.desktop did not pull in this change or I did not do it correctly.

Adding phpmyadmin as dependency for nextcloud:

    depends_on:
      - database-${SQL:-mysql}
      - redis
      - mail
      - ${PROXY_SERVICE:-proxy}
      - phpmyadmin
    extra_hosts:
      - host.docker.internal:host-gateway

Starting and stopping in docker.desktop:

There should be no need to add anything, please remove the depends line for now.
You need to start the container, so inside the nextcloud-docker-dev directory so „docker compose up -d phpmyadmin“. Then the container should be visible in desktop as well.

Ensure that you setup the hosts (there’s also a script for that in scripts/). Then connect via https://phpmyadmin.local (or http if you did not setup https)

1 Like

Thank you!

Well, if you execute it without any further parameters, it should log you into the DB server in an interactive console. If you wanted to add parameters to the command in the container, you could add them on the CLI while invoking it.