How to connect appsmith docker and mysql docker in local ubuntu 20.04(focal)OS

I had installed docker and configured appsmith container(latest) and mysql container(mysql 8.0.29) in my local machine Ubuntu 20.04 OS. But I couldn’t connect to mysql database from appsmith application. Following is the status shown in appsmith app.
“Appsmith server timed out when fetching structure. Please reach out to appsmith customer support to resolve this.” under DATA SOURCE in appsmith side menu.
Connection to mysql docker from local host is working fine.
mysql docker ip: 172.17.0.2, port 3306
$sudo docker exec -it mysql_docker bash


docker_compos.yml

version: “3”

services:
appsmith:
image: Docker Hub
container_name: appsmith
ports:
- “80:80”
- “443:443”
volumes:
- ./stacks:/appsmith-stacks
restart: unless-stopped
db:
image: mysql/mysql-server:latest
container_name: mysql_docker
ports:
- “3306:3306”


Provided all permission to database user and % against host in mysql.user table


appsith is running in 172.17.0.1

If anybody have solution, Please reply to this.

Hey! Please take a look at this thread -

Hey @appsmithapps, when configuring your datasource, can you try using db as the host instead of that IP address and see if that works please?

@sharat87
Hi thanks to your reply…
Following is the datasource interface in appsmith:

Connection Mode *: Read/Write
Host Address: 172.17.0.2
Port: 3306
Database name: (added)

How can add db instead of host?? I think host address is mandatory.

@pranav
Hi thanks to reply.
When run this command-- $ip addr show docker0 , following is output
+++++++++++++++++++++++++++++++++++++
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:d9:7f:b3:3b brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:d9ff:fe7f:b33b/64 scope link
valid_lft forever preferred_lft forever
++++++++++++++++++++++++++++++++++++++
When run this command …$sudo docker inspect mysql_docker, following is output

“Gateway”: “172.17.0.1”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“MacAddress”: “02:42:ac:11:00:02”,
“Networks”: {
“bridge”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: null,
“NetworkID”: “e65f26674f0e05802f3d65749f421976c601601834e0fe23b421b7d1e43b9678”,
“EndpointID”: “c91c83666a7696e79d5941d793d631d43ff93cd2f2af696dabe9a7377fefcdb0”,
“Gateway”: “172.17.0.1”,
“IPAddress”: “172.17.0.2”,
“IPPrefixLen”: 16,
“IPv6Gateway”: “”,
“GlobalIPv6Address”: “”,
“GlobalIPv6PrefixLen”: 0,
“MacAddress”: “02:42:ac:11:00:02”,
“DriverOpts”: null
}
}
+++++++++++++++++++++
when access this url via browser, http://172.17.0.2:3306, output is:

J���
8.0.29����Mc!dwa�ےےے�ےك����������aBeT=4=�caching_sha2_password�!��ے„#08S01Got packets out of order
++++++++
appsith is running in 172.17.0.1
But couldn’t connect to mysql from appsmith ->add datasource interface.

Sorry for not being clear. I’m suggesting to use db as the Host Address value instead of 172.17.0.2, when configuring your datasource on Appsmith.

@sharat87
When use db name instead of host address and trying to connect data source, showing error that “Unknown host exception Failed to resolve {db name}:3306”

In data source page of appsmith, there is a provision top enter following details. I tried both conditions

Connection Mode *: Read/Write
Host Address: (db name given)
Port: 3306
Database name: (db name given)


Connection Mode *: Read/Write
Host Address: 172.17.0.2
Port: 3306
Database name: (db name given)
(mysql docker is running in 172.17.0.2)

Still couldn’t connect to db.

@sharat87
when use ‘db’ instead of host address, showing following alert message is browser.
java.net.UnknownHostException: Failed to resolve ‘db’ after 2 queries

This is my docker-compose.yml file, which located at /var/appsmith/
++++++++++++++++++++++++++++
version: “3”

services:
appsmith:
image: Docker Hub
container_name: appsmith
ports:
- “80:80”
- “443:443”
volumes:
- ./stacks:/appsmith-stacks
restart: unless-stopped
db:
image: mysql/mysql-server:latest
container_name: mysql_docker
ports:
- “3306:3306”

# Uncomment the lines below to enable auto-update

labels:

com.centurylinklabs.watchtower.enable: “true”

auto_update:

image: containrrr/watchtower:latest-dev

volumes:

- /var/run/docker.sock:/var/run/docker.sock

# Update check interval in seconds.

command: --schedule “0 0 * ? * *” --label-enable --cleanup

restart: unless-stopped

+++++++++++++++++++++++++++++++++++++++++