0

I hope you could help me.

I'm trying to setup a docker with multiple MySQL container in ubuntu server.

docker-compose.yml

version: '3.1'

services:

  mysql-db_1:
    image: mysql:8.0.28-debian
    command: --sql_mode="" --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - '3306:3306'
    volumes:
      - ./data_1/files:/var/lib/mysql-files
      - ./data_1/data:/var/lib/mysql

  mysql-db_2:
    image: mysql
    command: --sql_mode="" --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - '3307:3307'
    volumes:
      - ./data_2/files:/var/lib/mysql-files
      - ./data_2/data:/var/lib/mysql

Everything is successfully built and I was able to connect to port 3306 however I can't connect to port 3307.

1 Answer 1

1

Your mysql-db_2 container port is invalid.

you can change it to 3307:3306

so it will be exposed at port 3307, but the container itself will be listening on port 3306

  mysql-db_2:
    image: mysql
    command: --sql_mode="" --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - '3307:3306'
    volumes:
      - ./data_2/files:/var/lib/mysql-files
      - ./data_2/data:/var/lib/mysql
Sign up to request clarification or add additional context in comments.

4 Comments

I also tried that, but when I check the show variables like '%port%', it still shows port 3306 even though I'm connected using -P 3307. Or it is normal?
please paste in your docker ps so i can understand better.
Everything is good. I'm just a bit confuse because when I connect on both ports (3306,3307) and execute show variables like '%port%' shows 3306. But when I check the content both have different records, so everything working fine now.
That is understandable. There are two 'players' here. 1. The docker container. 2. your computer. Your computer is the host for the docker container. Every time you set up a docker container you need a port exposed In the container and from your computer. For example : mysql-db_2 container will listen on port 3306 for HTTP request (or docker requests). and your computer will try to contact him using port 3306. Using docker ps is a better usage for showing container run time ports, because it shows you the computer and container ports.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.