Run MySQL on Port 3307 Using Docker Compose

In my case I could not change the Mysql port rather than 3306 until I add MYSQL_TCP_PORT

So sample:

version: '3.8'

volumes:
  mysql_data:
    driver: local

services:
  mysql:
    image: mysql:5.7
    volumes:
      - mysql_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: keycloak
      MYSQL_USER: keycloak
      MYSQL_PASSWORD: password
      MYSQL_TCP_PORT: 3307
    ports:
    - 3307:3307
    expose:
      - 3307
  keycloak:
    image: quay.io/keycloak/keycloak:latest
    environment:
      DB_VENDOR: MYSQL
      DB_ADDR: mysql
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_PASSWORD: password
      DB_PORT: 3307
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: Pa55w0rd
      # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the MySQL JDBC driver documentation in order to use it.
      #JDBC_PARAMS: "connectTimeout=30000"
    ports:
      - 8040:8080
    depends_on:
      - mysql

Variable SQL_INTERNAL_PORT probably has 3307 value. You need to change it to 3306.

Also, you can remove

    expose:
    - "${SQL_INTERNAL_PORT}"

lines. Mysql already exposes 3306 port.

All of the applications into cluster use internal ports (3306 in mysql case). External ports (in section ports) you need only for external word communication.

If you want to have several databases, you need to change docker-compose something like this:

version: '3'
services:
hackernews:
    image: prismagraphql/prisma:1.8
    restart: always
    ports:
    - "${CLIENT_PORT}:${INTERNAL_PORT}"
    environment:
    PRISMA_CONFIG: |
        port: $INTERNAL_PORT
        managementApiSecret: $PRISMA_MANAGEMENT_API_SECRET
        databases:
        default:
            connector: mysql
            host: mysql_first
            port: 3306
            user: root
            password: $SQL_PASSWORD
            migrations: true
        second:
            connector: mysql
            host: mysql_second
            port: 3306
            user: root
            password: $SQL_PASSWORD
            migrations: true
mysql_first:
    image: mysql:5.7
    restart: always
    environment:
    MYSQL_ROOT_PASSWORD: $SQL_PASSWORD
    ports:
     - 3307:3306
    volumes:
    - ./custom/:/etc/mysql/conf.d/my.cnf
    - mysql:/var/lib/mysql

 mysql_second:
    image: mysql:5.7
    restart: always
    environment:
    ports:
     - 3308:3306
    MYSQL_ROOT_PASSWORD: $SQL_PASSWORD