It sounds like you're new to Docker. You may want to spend some time reading through documentation and examples to get a better feel for how things work.
First, simply installing software doesn't necessarily make it run, and that is certainly the case with CentOS and other Red Hat variants. On a bare metal host, you would simply run systemctl start mariadb
to start it, but this only works because on a regular system, the /sbin/init
component of systemd is started as part of the boot process.
Inside a docker container, nothing is running by default. For example, if you were to run ps -fe
on your host, you would probably see hundreds of running processes.
If you were to run:
docker run centos ps -fe
You would see:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 11:12 ? 00:00:00 ps -fe
Because of this, you can't start services using the normal mechanism. You will instead need to (a) start the service manually and (b) ensure that you have started it such that it will stay in the foreground (because a Docker container exits when the foreground process exits or puts itself into the background).
If you take a look at the official mariadb image, you will see that it ultimately just calls mysqld
to start the service.
It sounds like you want to start mariadb inside a container and then try interacting it from within the same container. While this isn't the normal way of working with docker, you could...
$ docker run -it centos bash
[root@c1d6adf5c8bb /]# yum -y install mariadb-server
[root@c1d6adf5c8bb /]# /usr/libexec/mariadb-prepare-db-dir mariadb.service
[root@c1d6adf5c8bb /]# /usr/bin/mysqld_safe --basedir=/usr &
[root@c1d6adf5c8bb /]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
More typically, you would use a Dockerfile
to build a mariadb image (or just use the official one), start it, and then use mysql
on your host or in another container to interact with that mariadb instance.
Best Answer
This is because
mysqld_safe
silently fails if it doesn't have permissions and it can't write to the log as in the event of being run as a regular user.Instead run,