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

129
Vistas
Mariadb multi stage container with an existing database

I need to create a container with an existing database and operate some actions on it before distribute it. In production, I've got some really big databases:

[root]# ls /home/db-backup/test/prepare/26_06_2020/full/
ibdata1        
ib_logfile0    
ib_logfile1    
ibtmp1         
mysql
performance_schema
my_existing_database1
my_existing_database2
my_existing_database3

I just need to publish a container with my_existing_database1 for my team.

I tried many Dockerfile but I can't find a way do to it and I don't understand why. Here a simplified Dockerfile :

FROM mariadb:latest as builder

ENV MYSQL_ALLOW_EMPTY_PASSWORD yes

# for easier debug, i will remove that in prod
RUN sed -i '/\[mysqld\]/a plugin-load-add = auth_socket.so' /etc/mysql/my.cnf

WORKDIR /initialized-db

COPY ibdata1 .
COPY mysql ./mysql
COPY performance_schema ./performance_schema
COPY my_existing_database1 ./my_existing_database1
COPY db-init.sh /docker-entrypoint-initdb.d/

RUN chown mysql:mysql . \
  && chmod 660 ibdata1 \
  && chmod +x /docker-entrypoint-initdb.d/db-init.sh

RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db", "--aria-log-dir-path", "/initialized-db"]

# No file named test
RUN ls /initialized-db/

FROM mariadb:latest
COPY --from=builder /initialized-db /var/lib/mysql

As you can see, I try to execute my script db-init.sh. Simplified version :

#!/bin/bash
set -e -x

mysql -u root -e "CREATE USER 'test'@'%' IDENTIFIED BY 'test';"
touch /initialized-db/test

Unfortunetly, my script is not executed as the file test is not created. I try to bypass the /usr/local/bin/docker-entrypoint.sh with my own script (copy/paste of the file with some edit) but it's not working either (user and file test not created).

Can you help me on this one please?

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

0

You should preferably mount a directory for the data and distribute it then extra.

If you must distibute it with the container itself, you should be able to edit the config of that database to use a custom data directory and initialize your databases in it with RUN and COPY.

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