Can’t access MySQL db from SQLyog after running docker compose file

I am running a compose file which is installing mysql in the container and initialized the db. I can enter into the container and see the tables which are created.

But when I try to login to MySQL DB using SQLyog, can’t connect this time. I was using the public IP of my ec2 instance. In the failed case I was using port 3308 of the host machine. If I use the default port(3306) then it gets connected !!! But in port 3306, I need to run another MySQL server. So to run in port 3308 of the host machine, what to do from my side?

This is my compose file:

cat docker-compose.yml

version: '3' 
volumes:
        failed_db_data: {}

services:
    faileddb:
        build:
            context: .
            dockerfile: ./faileddb/Dockerfile
            args:
                - database=${FAILED_DB}
                - password=${FAILED_DB_PASSWORD}
        image: failed_db_image
        volumes:
            - failed_db_data:/var/lib/mysql
        ports:
            - "3308:3308"

This is the Dockerfile:

cat faileddb/Dockerfile

FROM mysql:5.7.15

ARG database
ARG password

MAINTAINER me
ENV MYSQL_DATABASE=${database} 
    MYSQL_ROOT_PASSWORD=${password}
ADD ./faileddb/failed100.sql /docker-entrypoint-initdb.d
EXPOSE 3308

This is .env file

cat .env

#FAILED_DB
FAILED_DB_PORT=3308
FAILED_DB=failed
FAILED_DB_USER=root
FAILED_DB_PASSWORD=123

This is my tree command, from where the compose file exists:

tree -a
.
├── .env
├── docker-compose.yml
└── faileddb
    ├── Dockerfile
    └── failed100.sql

1 directory, 4 files

Now, I am building it:

docker-compose up -d

Creating network "reve_default" with the default driver
Creating volume "reve_failed_db_data" with default driver
Building faileddb
Step 1/7 : FROM mysql:5.7.15
5.7.15: Pulling from library/mysql
6a5a5368e0c2: Pull complete
0689904e86f0: Pull complete
486087a8071d: Pull complete
3eff318f6785: Pull complete
3df41d8a4cfb: Pull complete
1b4a00485931: Pull complete
0bab0b2c2630: Pull complete
264fc9ce512d: Pull complete
e0181dcdbbe8: Pull complete
53b082fa47c7: Pull complete
e5cf4fe00c4c: Pull complete
Digest: sha256:966490bda4576655dc940923c4883db68cca0b3607920be5efff7514e0379aa7
Status: Downloaded newer image for mysql:5.7.15
 ---> 18f13d72f7f0
Step 2/7 : ARG database
 ---> Running in 3d0dedd7e51f
Removing intermediate container 3d0dedd7e51f
 ---> bf054f294f4b
Step 3/7 : ARG password
 ---> Running in 0f09ff73a201
Removing intermediate container 0f09ff73a201
 ---> 9948007a0fc0
Step 4/7 : MAINTAINER me
 ---> Running in 4b11b4bba056
Removing intermediate container 4b11b4bba056
 ---> be09d8a1ad2a
Step 5/7 : ENV MYSQL_DATABASE=${database}     MYSQL_ROOT_PASSWORD=${password}
 ---> Running in 0ad7701bc7d4
Removing intermediate container 0ad7701bc7d4
 ---> 9c28be0c1367
Step 6/7 : ADD ./faileddb/failed100.sql /docker-entrypoint-initdb.d
 ---> d8ab45637fca
Step 7/7 : EXPOSE 3308
 ---> Running in f3eda2d36bbe
Removing intermediate container f3eda2d36bbe
 ---> 4b16e6a06593
Successfully built 4b16e6a06593
Successfully tagged failed_db_image:latest
WARNING: Image for service faileddb was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating reve_faileddb_1 ... done

Checking if it is running fine:

docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
217acd44a1df        failed_db_image     "docker-entrypoint.s…"   8 seconds ago       Up 7 seconds        3306/tcp, 0.0.0.0:3308->3308/tcp   reve_faileddb_1

entered into the container now:

docker exec -it 217acd44a1df bash

entered in MySQL and checked if tables are ok, found those okay as well.

mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| failed             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
mysql> use failed;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Now I am trying to login using SQLyog(from my windows machine using public IP of ec2 instance):

SQLyog can't connect host machine 3308 port

What am I missing here? Thanks in advance.

Source: StackOverflow