-
Notifications
You must be signed in to change notification settings - Fork 1
Mariadb
-
Initial Configuration for MariaDB
-
Create the Docker image configuration file
Dockerfilefor MariaDB in the path described below via the terminal:mkdir -p rootInception/srcs/requirements/mariadb/Dockerfile
-
Update the
docker-compose.ymlfile by adding a service for MariaDB so that when executed, it can compose the MariaDB container as well, as shown below:version: "3.8" services: nginx: build: requirements/nginx/. container_name: nginx ports: - "80:80" volumes: - .web:/var/www/html wordpress: build: requirements/wordpress/. container_name: wordpress volumes: - .web:/var/www/html mariadb: build: requirements/mariadb/. container_name: mariadb
-
Fill in the
Dockerfilefor MariaDB so that it can configure a Docker image that will be executed later as shown below:FROM debian:bullseye RUN apt update && apt upgrade -y && apt install -y mariadb-server ENTRYPOINT ["mysqld_safe"]
👉🏼 These are the minimum configurations for MariaDB to run inside the container. We now need to start the MariaDB container, enter it, and copy the content of some default files created during the MariaDB installation in the system, which should be modified for the project's functionality.
-
Execute the command that will create and start the containers, as described below, via the terminal:
docker compose up --build
👉🏼 For the test to work, clear all created Docker images and recreate them from the updated Dockerfile and docker-compose file configurations.
-
-
Configuration File Copy from Host(Automatic Mode)
-
Execute the copy command via the container manager compose, to copy the default file from the MariaDB container to the host, as described below:
docker cp mariadb:/etc/mysql/mariadb.conf.d/50-server.cnf ./srcs/requirements/mariadb/conf/.
👉🏼 The command above will only work if the
mariadbcontainer is running. After copying the file to the host, you can pause the container, delete it, and remove the created image.
-
-
Customize MariaDB Configuration
-
Uncomment/Change the security and permission settings in the
50-server.cnffile copied from the MariaDB container that specify that MariaDB should run as therootuser in the system:user = mysql #Original line user = root #Modified line
👉🏼 The
datadirandtmpdirconfigurations may be commented out and might need to be uncommented. Below is an explanation of what they do:- tmpdir → Specifies the directory where the MariaDB server stores its temporary files.
- datadir → Specifies the directory where the MariaDB server stores its database files.
-
Change the security setting that specifies the
IPaddress andNetworkwhere the MariaDB database server listens for connections from localhost to the local network in the50-server.cnffile copied from the MariaDB container:bind-address = 127.0.0.1 #Original line bind-address = mariadb #Modified line
-
Add the command to copy the modified
50-server.cnfconfiguration file into the/etc/mysql/mariadb.conf.d/directory in the MariaDB container to replace the original file with the customized one in the Dockerfile for MariaDB:FROM debian:bullseye RUN apt update && apt upgrade -y && apt install -y mariadb-server COPY conf/50-server.cnf /etc/mysql/mariadb.conf.d/. ENTRYPOINT ["mysqld_safe"]
-
Add the command to create the
/run/mysqlddirectory, which will be responsible for storing temporary files and important files for running MariaDB, such as the PID file and connection socket in the Dockerfile for MariaDB:FROM debian:bullseye RUN apt update && apt upgrade -y && apt install -y mariadb-server COPY conf/50-server.cnf /etc/mysql/mariadb.conf.d/. RUN mkdir /run/mysqld ENTRYPOINT ["mysqld_safe"]
👉🏼 To verify the need for the
/run/mysqlddirectory, while the MariaDB container is running, you can check the contents of the/etc/mysql/mariadb.cnffile with thedocker exec -it mariadb cat /etc/mysql/mariadb.cnfcommand and verify that there is a line describing that the connection socket file will be stored at the path/run/mysqld/mysqld.sock, which makes it necessary to have the/run/mysqlddirectory, which (probably) is not created automatically during the MariaDB installation.👉🏼 At this stage, you can test the functionality of the containers by rebuilding the images and starting them all. Finally, you can enter the MariaDB container with the
docker exec -it mariadb /bin/bashcommand and enter the MariaDB CLI through themysql -u root -pcommand to navigate the data and verify the creation of the database and tables.
-