title: How to expose mysql port?
body: <p>I'm trying to expose the port <code>3310</code> to allow remote <code>MySQL</code> connection. So far, I have this configuration:</p>
  <pre><code>  database:
      container_name: sfapi_db
      restart: always
      ports:
        - 3310:3306
      build:
        context: ./docker/database
      environment:
        - MYSQL_DATABASE=${DB_NAME}
        - MYSQL_USER=${DB_USER}
        - MYSQL_PASSWORD=${DB_PWD}
        - MYSQL_ROOT_PASSWORD=${DB_PWD_ROOT}
      volumes:
        - dbdata:/var/lib/mysql
        - type: bind
          source: ./docker/database/my.cnf
          target: /etc/mysql/my.cnf
  </code></pre>
  <p>and this is the Dockerfile:</p>
  <pre><code>FROM mariadb:latest
  
  CMD [&quot;mysqld&quot;]
  
  EXPOSE 3310
  </code></pre>
  <p>here the my.cnf:</p>
  <pre><code>[client-server]
  # Port or socket location where to connect
  port = 3310
  socket = /run/mysqld/mysqld.sock
  
  # Import all .cnf files from configuration directory
  !includedir /etc/mysql/conf.d/
  !includedir /etc/mysql/mariadb.conf.d/
  </code></pre>
  <p>when I run <code>docker-compose up --build -d</code> and access to the container list, I get:</p>
  <p><a href="https://i.stack.imgur.com/LS6GX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LS6GX.jpg" alt="enter image description here" /></a></p>
  <p>I also opened the port on the server using <code>sudo ufw allow 3310</code>. Also, I cannot use the port 3306 'cause it's used by another container, that's why I'm using 3310.</p>
  <p>For some reason, when I go <a href="https://www.yougetsignal.com/tools/open-ports/" rel="nofollow noreferrer">there</a> and check if the port 3310 is opened, I always get that is closed.</p>
  <p>How can I fix this?</p>