How to change mysql port in docker

Hi,
I have a non docker mysql instance running in my ubuntu serverI
Then on the same server, to run another pplication, i created a dockerized version and trying to run it, resulting in error “…0,0,0,0:3306: bibd: already in use” error
So I did changes in docker-compose.yml config file to change it to 3360:
database > ports: “3360:3360” and
databse > environment : MYSQL_TCP_PORT: 3360
Databse container is not running
Trie to run it and I get the same error. It seems that docker does not read or does not follown the changes made in the config file
What can be the problem?

Your description is unclear. Note that we don’t know anything about your environment so the fact that you understand very short parts like

doesn’t mean we know what it is supposed to mean or what image you are using, so please explain your issue in more details.

By the way you don’t have to change the listening port in the container. That’s the point. Mysql can listen on the container port, you should just not use the same port on the left side of the port mapping.

docker run -d --name mysql -p 3360:3306 mysql:VERSIONTAG

Hi Rimelek, thank you for your answer!!
I’l try to describe the problem from another angle. The following is a copy of my docker-compose.yml file:


version: “3.8”

services:
cache:
image: redis:4-alpine

database:
image: mysql:8.0-oracle
ports:
- “3360:3360”
volumes:
- “./docker/database/:/docker-entrypoint-initdb.d/”
- “./docker/database/mysql:/var/lib/mysql”
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: ‘yes’
MYSQL_DATABASE: “fleetbase”
MYSQL_TCP_PORT: 3360


you can see here that I changed mysql port from the default value (3306) to 3360.
When I try to start the container with

sudo docker start fleetbase-database-1 (fleetbase-database-1 is name of the container running mysql)

I get the following error:

Error response from daemon: driver failed programming external connectivity on endpoint fleetbase-database-1 (3db9d4d94fa7023ce78edbbd9c707d7da8aa4cfa811c01ac8dc10c0713216410): Error starting userland proxy: listen tcp4 0.0.0.0:3306: bind: address already in use
Error: failed to start containers: fleetbase-database-1

As you can see docker is still trying to use port 3306. Y dont know why is not reading the change made in docker-compose.yml


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```