Custom configuration in container not overwritten

Hi, I’ve got a problem with a mariadb container on balena.
I’m trying to overwrite the custom.cnf file located in the container in /etc/mysql/conf.d via Dockerfile command COPY custom.cnf /etc/mysql/conf.d/ (the custom.cnf file in my directory is right next to the Dockerfile), but the file in the container remains the same.

Here’s the docker-compose.yml:
container_name: webmacs.mariadb
hostname: webmacs.mariadb
- 3306:3306
- "webmacs-data:/config/databases"
privileged: true
context: ./webmacs.mysql
dockerfile: Dockerfile

And the Dockerfile:

FROM linuxserver/mariadb:arm32v7-latest
# Install extra system packages
RUN curl -sL | bash - && \
apt-get update && \
apt-get install --no-install-recommends -y \
unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY custom.cnf /etc/mysql/conf.d/

If you could help I’d appreciate it. Thanks!

Hello Krestin,
I tested overwriting in Dockerfile just now. If you want to overwrite the custom.cnffile in your container, the COPYcommand destination path needs to be absolute. Hence, it should be something like COPY custom.cnf /etc/mysql/conf.d/custom.cnf. Do try it out and let us know if it works out for you. Thanks!

Thank you for your answer!
I tried using the absolute path but unfortunately it still doesn’t work. Do you have any other ideas?

Hi there, can you share your Dockerfile snippet (the part where you make the overwrite)? please redact any sensitive info, I just want to make sure the commands and their ordering is correct :slight_smile:

Hi, the current Dockerfile is:

FROM linuxserver/mariadb:arm32v7-latest
# Install extra system packages
RUN curl -sL | bash - && \
apt-get update && \
apt-get install --no-install-recommends -y \
unzip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY custom.cnf /etc/mysql/conf.d/custom.cnf

Hello, the file you are trying to COPY should be available in the context you are passing to docker build In the compose snippet above I see context: ./webmacs.mysql so that should be the only file available for the build. If that file is just next to the dockerfile something like context: . should work fine.

is the folder under my docker-compose-file, where the Dockerfile and the custom.cnf I want to copy are located. So it should be able to find the custom.cnf there, right?

Hi again,

To clarify a bit further on my colleague’s answer, since you are specifically defining a context that does not include the file you wish to copy, Docker won’t be able to find that file. If you alter your docker-compose.yml to instead pass a context of context: ., Docker will see both your subdirectory called webmacs.mysql as well as your custom.cnf. We wrote a masterclass covering some of the commonly-used Dockerfile directives that might help explain that further, feel free to give that a read as well:

I’m still not sure I get the problem.
I added the line COPY custom.cnf /etc/test/custom.cnf
to the Dockerfile right before the line where I want to COPY it to the actual directory (COPY custom.cnf /etc/mysql/conf.d/custom.cnf).
The custom.cnf file then ends up in /etc/test/ so Docker is actually able to find the file and context should not be the issue,right? Or do I still miss the point?

Hi there,

I think the confusion here is that ./webmacs.mysql sounds like a file rather than a folder. Can you confirm that this is actually a folder and within this folder is your docker file as well as the custom.cnf file?

yes you are correct, webmacs.mysql is a folder.

Hey @kerstin_boergers it might be best to perhaps push your code up to github or somewhere to share with us as we can get a better sense of how things are laid out in your repo and reproduce it our side.

Okay here are the corresponding parts of the code:


I looked into it and I think I would start by simplifying your compose file build section. I built the image directly in docker and it copied the config without issue. So try this:

Instead of these lines:

Use build: ./webmacs.mysql instead. And if that doesn’t work then drop the periods from the dir/service names as this feels “wrong” to me.

Hope that helps.

Okay I used build: ./mysql instead (with the renamed folder webmacs.mysql->mysql). Are there more things I could do?


Are the settings still not being applied?

I would suggest first confirming that the path /etc/mysql/conf.d/custom.cnf is the right one?
It seems like the image you are using expects db settings to be in /config

if copying file to /config you still see that it is not working maybe it could be related to permissions as describe here ?

then try adding another line after COPY custom.cnf .. to change persmissions

RUN chmod 644 /etc/mysql/conf.d/custom.cnf or
RUN chmod 644 /custom.cnf

Hope this helps

Oh, yes the actual settings are in /config instead of /etc/mysql/conf.d now it works. Thank you for your help! :slight_smile: