title: How to connect mysql database inside Docker container remotely
body: <p>I have MySQL database hosted on CentOS with docker container. It is working fine. Now I want to connect that database from my laptop remotely. I use server ip (digital ocean's public ip) with port 3307 or 3306 but it is not working. My I know how to connect database inside docker container.</p>
  <p>docker-compose.yml</p>
  <pre><code>version: &quot;3.7&quot;
  services:
    db:
      container_name: mycontainer-db
      image: asia.gcr.io/myserver-bf003/mydatabase/db
      restart: always
      volumes:
        - ./db/data/:/var/lib/mariadb/data
      environment:
        MARIADB_ROOT_PASSWORD: xxxxxx
        MARIADB_DATABASE: mydatabase
      expose:
         - 3306
      ports:
        - &quot;3307:3306&quot;
      networks:
        - gita
  </code></pre>
  <p>Docker</p>
  <pre><code>FROM mariadb:latest
  RUN apt-get update &amp;&amp; apt-get install -y locales locales-all
  RUN locale-gen en_US.UTF-8
  ENV LC_ALL=en_US.UTF-8
  ENV LANG=en_US.UTF-8
  ENV LANGUAGE=en_US.UTF-8
  EXPOSE 3306
  ENV MARIADB_ROOT_PASSWORD=&quot;xxxxxx&quot;
  ENV MARIADB_DATABASE=&quot;mydatabase&quot;
  COPY ./init/ /docker-entrypoint-initdb.d/
  </code></pre>