Mariadb started failed in docker

I have a docker file like this

FROM mariadb:10.6

RUN service mariadb start && echo “mariadb started”

ENTRYPOINT [“/bin/bash”, “-c”, “service mariadb start && /bin/bash”]

When i run dokcer build --progress=plain --no-cache ./ -t 1 the output of docker build is

0.832 Starting MariaDB database server mariadbd
32.07 …fail!

Dockerfile:7

5 | COPY asterisk-db.sql ./callflow/
6 |
7 | >>> RUN service mariadb start && echo “mariadb started”
8 |
9 | # Update my.cnf for more detailed error logging

ERROR: failed to solve: process “/bin/sh -c service mariadb start && echo "mariadb started"” did not complete successfully: exit code: 1

All related system information:

OS: Debian GNU/Linux 11 (bullseye)
Docker version: 24.0.7, build afdd53b

All I did was clone from mariadb image and start the service. Why it started failed? Sorry for my bad english

This is totally not how it works :sweat_smile:

The Dockerfile is used to build a Docker image, which can later be started as a process.

run in Dockerfile can be used to run a temporary command, like apt install to add packages to the image. But you shouldn’t start a continuous service there.

The service could be started in entrypoint, which is executed when the built image is actually started.

I recommend to check one of the many Docker tutorials or the documentation.

Why do you want to change the default database by overwriting the Dockerfile, what do you want to achieve?

it is possible to see the original Dockerfile in the repo (example link) or use docker inspect to see what values are used by the original image.

I just want to run some script so that it create user and databases, but let me look at the docker documentation for this. Thank you

Check those two links [1, 2].