Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

809
Vistas
How to configure mariadb docker-compose file to use other port than 3306?

I cannot get mariadb to use another port other than 3306 when running it in a docker container using a docker-compose file.

I have already read the mariadb/docker documentation, searched online and conducted my own experiments.

  1. docker-compose file:
version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    environment:
    - MYSQL_ROOT_PASSWORD=mypassword
    - MYSQL_TCP_PORT=33030
    - MYSQL_UNIX_PORT=33020
    ports:
    - "33020:33020"
  1. Dockerfile:
FROM: mariadb: 10.3.14
COPY mydbscript.sql /docker-entrypoint-initdb.d/
EXPOSE 33020
CMD ["mysqld"]

It never uses port 33020. It still uses port 3306. How can I pass the port dynamically via the docker-compose file at run-time?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You need to replace the default my.cnf to specify a custom port for MariaDB/MySQL:

cd /where/your/docker-compose.yml/located

docker run -it mariadb cat /etc/mysql/my.cnf > my.cnf

# use any text editor your like to open my.cnf, search for "port = 3306"
# and replace it to the port you like to have.

Configure your docker-compose.yml like this:

version: '3.1'

services:

  db:
    image: mariadb
    restart: always
    volumes:
    - type: bind
      source: ./my.cnf
      target: /etc/mysql/my.cnf
    environment:
    - MYSQL_ROOT_PASSWORD=mypassword
    # add your other configurations here
over 4 years ago · Santiago Trujillo Denunciar

0

The container image is statically bound to :3306. If you wish to change this, you'll need to build a new image and configure the database to run elsewhere.

However, Docker permits you to map (publish) this as a different port :33020.

The correct way to do this is to:

  • docker-compose MYSQL_TCP_PORT=3306
  • docker-compose ports: - "33020:3306"
  • Dockerfile EXPOSE 3306 (unchanged)

Containers (internally) will correctly reference :3306 but externally (from the host) the database will be exposed on :33020.

NB Within docker-compose (network), other containers must continue to reference the database on port :3306.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda