I'm trying to have multiple MariaDB Docker containers on my server. First is using 3307 -> 3306 port Secondary is using 3311 -> 3310 port
But, for the second, docker still binding the 3306 port...
Docker Compose :
version: '3.7'
services:
mariadb:
image: ${MARIADB_VERSION}
restart: on-failure
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- ${PORTS_MARIADB}
volumes:
- db:/var/lib/mysql'
container_name: ${DB_CONTAINER_NAME}
networks:
- network
networks:
network:
name: ${NETWORK}
volumes:
db:
.env.prod (only db part):
DB_VERSION=mariadb-10.6.4
MARIADB_VERSION=mariadb:10.6.4
MYSQL_ROOT_PASSWORD=fzefzfezfze
MYSQL_DATABASE=db
MYSQL_USER=db
MYSQL_PASSWORD=fzefzezfefze
PORTS_MARIADB=3311:3310
Docker container ls :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81849c7db9f8 mariadb:10.6.4 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 0.0.0.0:3311->3310/tcp, :::3311->3310/tcp db_prod
Is there a way to "unbind" this port?
Thanks
CodePudding user response:
The Docker Image itself "EXPOSEs" port 3306. The fact that you bind port 3310 to port 3311 is something different. If you want the db to be available on port 3310 on the Host, you should use "3310:3306" string.
Short explaination
In Ports section there are 2 numbers: "AAAA:BBBB"
BBBB
This is the port which is exposed inside the container. The Image-software does something on this port. In case of MariaDB it is always port 3306.
AAAA
This is the port on the Host you want opened. And if a request on the Host to that port comes in, it is the same as port BBBB on the Container.
CodePudding user response:
If you want to use port 3310 instead of default 3306 for MariaDB, you need to add environment variable MYSQL_TCP_PORT
to your docker compose file:
environment:
...
MYSQL_TCP_PORT: 3310