Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!