Hi!
I have a problem with port mapping (I created a topic for it). In order to find a solution, I switched from Docker Desktop to Docker Engine.
Unfortunately, my user inside the Docker container has no file permissions in bound volumes, when I’m using Docker Engine. But when I’m using Docker Desktop, my user inside the Docker container has these file permissions.
Due to the missing file permissions, MariaDB exits with an error and the container stops.
Could somebody help me, getting it to work using Docker Engine, please?
Thank you in advance,
Bernhard
Linux: Ubuntu 24.04.2
Docker Engine (docker --version): Docker version 28.0.2, build 0442a73
docker-compose.yml
# Note: Values have been anonymized.
name: my-project-name
networks:
database:
project:
driver: macvlan
driver_opts:
parent: my-network-interface
ipam:
config:
- gateway: 192.168.59.1
subnet : 192.168.59.0/24
services:
mariadb:
build:
context: /my/build/context/path
dockerfile: /my/dockerfile/path
container_name: my-project-name-mariadb
entrypoint: /my/entrypoint/path
env_file: /my/env_file/path
networks:
database:
project:
ipv4_address: 192.168.59.123
ports:
- host_ip: 192.168.59.123
mode: host
protocol: tcp
published: 1234
target: 1234
volumes:
- bind:
selinux: Z
source: ./database
target: /my/bind/database/target/path
type: bind
- bind:
create_host_path: true
selinux: Z
source: ./database/data
target: /my/bind/database/data/target/path
type: bind
- bind:
create_host_path: true
selinux: z
source: ./log
target: /my/bind/log/target/path
type: bind
Dockerfile:
FROM mariadb:latest
SHELL ["/bin/bash", "-ec"]
RUN /bin/bash /path/to/provisioner/sh/provisioner.sh
USER docker: docker
provisioner.sh:
# Create a Docker user.
if [ -z "$APK" ]; then
groupadd -r docker
useradd -g docker -m -r -s /bin/bash docker
else
addgroup -S docker
adduser -D -G docker -s /bin/bash -S docker
fi
echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/docker
# Adapt file permissions for the created docker user.
chown -R docker:docker /home/docker
chown -R docker:docker /tmp/*
chown -R docker:docker /path/to/project/data
entrypoint.sh:
#!/bin/bash
# Initialize project.
cd /path/to/project/data
# Do some stuff with the project data (unrelated to Docker).
# Providing a custom entrypoint overwrites the default entry point of the image. Call it, to get the container to work.
docker-entrypoint.sh mariadbd # Default entry point of container "mariadb:latest".
MariaDB log file:
2025-03-25 10:04:14 0 [Note] Starting MariaDB 11.7.2-MariaDB-ubu2404 source revision 80067a69feaeb5df30abb1bfaf7d4e713ccbf027 server_uid yJhRsRqu9LWL8EuEzXLjcALXXAA= as process 31
2025-03-25 10:04:14 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
2025-03-25 10:04:14 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
2025-03-25 10:04:14 0 [ERROR] Aborting