I am not able to build an image using this Dockerfile when i try to run build process inside a ubuntu VM. However, i dont see any issues if i run the build process inside a jenkins container.

FROM mysql:latest as builder
RUN [“sed”, “-i”, “s/exec "$@"/echo "not running $@"/”, “/usr/local/bin/docker-entrypoint.sh”]
COPY enterprise.sql /docker-entrypoint-initdb.d/
COPY databases.sql /docker-entrypoint-initdb.d/
RUN [“/usr/local/bin/docker-entrypoint.sh”, “mysqld”, “–disable-log-bin”, “–default-authentication-plugin=mysql_native_password”, “–datadir”, “/initialized-db”]

FROM mysql:latest
LABEL org.label-schema.project=np
COPY --from=builder /initialized-db /var/lib/mysql

I get such an error:

[builder 5/5] RUN [“/usr/local/bin/docker-entrypoint.sh”, “mysqld”, “–disable-log-bin”, “–default-authentication-plugin=mysql_native_password”, “–datadir”, “/initialized-db”]:
0.115 2023-09-12 13:43:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
0.318 2023-09-12 13:43:19+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
0.327 2023-09-12 13:43:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.1.0-1.el8 started.
0.518 2023-09-12 13:43:19+00:00 [Note] [Entrypoint]: Initializing database files
0.533 mysqld: Can’t create directory ‘/initialized-db/’ (OS errno 17 - File exists)
0.533 2023-09-12T13:43:19.904190Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
0.533 2023-09-12T13:43:19.906323Z 0 [Warning] [MY-010918] [Server] ‘default_authentication_plugin’ is deprecated and will be removed in a future release. Please use authentication_policy instead.
0.533 2023-09-12T13:43:19.906348Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.1.0) initializing of server in progress as process 79
0.533 2023-09-12T13:43:19.906423Z 0 [ERROR] [MY-010338] [Server] Can’t find error-message file ‘/usr/share/mysql-8.1/errmsg.sys’. Check error-message file location and ‘lc-messages-dir’ configuration directive.
0.533 2023-09-12T13:43:19.907649Z 0 [ERROR] [MY-013236] [Server] The designated data directory /initialized-db/ is unusable. You can remove all files that the server added to it.
0.534 2023-09-12T13:43:19.907766Z 0 [ERROR] [MY-010119] [Server] Aborting
0.534 2023-09-12T13:43:19.907949Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.1.0) MySQL Community Server - GPL.
0.534 2023-09-12T13:43:19.908187Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.

Seems like a permissions issue. The MySQL installation says it’s switching to the mysql user, so you need to give that user access to the folder. Try adding this line just below your ENV vars (before you run docker-entrypoint.sh):

RUN chmod -R u+rwx /initialized-db && chown -R mysql:mysql /initialized-db

This issue comes up when i try to build the image with multi-arch support. I am able to build it with docker build command. But, while using ‘docker buildx build --platform linux/amd64,linux/arm64’ i get this error