1

I'm working with node, docker, mysql and sequelize and am trying to connect sequelize to mysql container running on docker. It will only connect through port 3306 despite me having changed the "ports" to 3308-3308. When i look up the running containers i get the following for the mysql database:

ticketgo_database_1      docker-entrypoint.sh mysqld    Up      3306/tcp,                   
                                                                0.0.0.0:3308->3308/tcp

Which explains why it can only connect to port 3306 but I need to change the connection port from 3306 since that port is busy on my computer. How can i do that?

Mysql container:

  database:
    image: mysql
    environment:
      MYSQL_DATABASE: "ticketgo"
      MYSQL_ROOT_PASSWORD: "pass"
    volumes:
     - "./sql:/docker-entrypoint-initdb.d"
    ports:
    - "3308:3308" 

2 Answers 2

1

I guess your app is managed by docker-compose as well. There is no need to change which port is MySQL listening in its own container. Leave squelize connecting to databade:3306 and either do not specify port mapping in MySQL docker compose config or specify: 3308:3306 which means that port 3308 on host will be mapped to the 3306 container port. This does not mean that MySQL will listen to the 3308. It will be continuing listening in its container 3306, and a new port 3308 on the host will be mapped to it.

Only specify a port mapping if you need to access MySQL from outside docker-compose services (from another app on your host or a MySQL GUI for example)

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately remapping the container port to 3308 didn't enable sequelize connection through that port. It still can only connect through port 3306. The reason i want to connect through another port is because i get a error-message when trying to connect through 3306 which says that "port 3306 is already in use". The strange thing though is that i don't use port 3306 for anything else....
Could it be that I have another Mysql session running somewhere else on my computer? That only makes it possible to connect through 3306? How would I go by checking that?
0

In Port section, change second Port to any you want "3308:3309";

Or You can do this in she'll by -p 3309:3308

2 Comments

As you see in the docker.yml file I have changed ports to 3308:3308 but when i try to connect sequelize to the mysql-database it will only connect through 3306 which is what i want to change
@Oscar you shouldn't change both of them! In docker.yml just change secound part of port. Why? becouse it connect Host(Your PC or Server) port to Gust(Docker Container) port. So: -p 3308:3306

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.