Map /var/lib/mysql from container to nfs share

Hello,

1st time posting here, I hope I respect every forum’s rules.

I have to run my MySQL container on a new machine of my company.
This is the setup :

  • Docker Compose version v2.26.1
  • Red Hat Enterprise Linux release 8.9 (Ootpa)
  • mysql:8.0.33

New things are the machine is running on AWS cloud, it is RHEL8 intead of 7, and storage for my database is now a shared storage (NFS3).

I’m not able to run this container on the shered storage.
Everything is working fine if I map to a local folder but storage team decided my DB volumetry is given on shared storage …

1 - 1st try with the original version

services:
  mysql:
    container_name: npi360gen2-mysql
    image: mysql:8.0.33
    hostname: mysql
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_HOST: '%'
      MYSQL_HOST: ${MYSQL_HOST}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    networks:
      - npi360gen2-net
    ports:
      - 3306:3306
    restart: no
    volumes:
      - /appl/cld_npi360_vol11/database/mysql-persisting-data:/var/lib/mysql

networks:
  npi360gen2-net:
    driver: bridge

/appl/cld_npi360_vol11 is the mounted shared storage.
In this 1st version, I’ve try to map /var/lib/mysql to the NAS storage that is already mounted on the machine.
It doesnt work I have this strange error :

docker compose up
[+] Running 1/2
 ✔ Network docker_npi360gen2-net  Created                                                                                                                                                         0.1s
 ⠋ Container npi360gen2-mysql     Created                                                                                                                                                         0.0s
Attaching to npi360gen2-mysql
npi360gen2-mysql  | 2024-05-14 11:38:00+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
npi360gen2-mysql  | 2024-05-14 11:38:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
npi360gen2-mysql  | 2024-05-14 11:38:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
npi360gen2-mysql  | 2024-05-14 11:38:01+00:00 [Note] [Entrypoint]: Initializing database files
npi360gen2-mysql  | mysqld: [Warning] World-writable config file '/etc/my.cnf' is ignored.
npi360gen2-mysql  | mysqld: Can't create directory '/var/lib/mysql/' (OS errno 17 - File exists)
npi360gen2-mysql  | 2024-05-14T11:38:01.225265Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
npi360gen2-mysql  | 2024-05-14T11:38:01.225282Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.33) initializing of server in progress as process 81
npi360gen2-mysql  | 2024-05-14T11:38:01.227927Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
npi360gen2-mysql  | 2024-05-14T11:38:01.227955Z 0 [ERROR] [MY-010119] [Server] Aborting
npi360gen2-mysql  | 2024-05-14T11:38:01.228097Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.33)  MySQL Community Server - GPL.
npi360gen2-mysql exited with code 1

2 - 2nd try : map /var/lib/mysql to a NFS volume (I think it should be the right way)

services:
  mysql:
    container_name: npi360gen2-mysql
    image: mysql:8.0.33
    hostname: mysql
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_HOST: '%'
      MYSQL_HOST: ${MYSQL_HOST}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    networks:
      - npi360gen2-net
    ports:
      - 3306:3306
    restart: no
    volumes:
      - db:/var/lib/mysql
      - /opt/npi360/config/mysql8.cnf:/etc/my.cnf

networks:
  npi360gen2-net:
    driver: bridge

volumes:
  db:
    driver: local
    driver_opts:
      type: nfs
      o: addr=<<my_media_server_IP>>,rw
      device: :/stv_cld_npi360_vol11/q

(note : I confirm that ‘sudo mount -t nfs <<my_media_server_IP>>:/stv_cld_npi360_vol11/q /appl/tst-thibault’ is working properly.)

This version of dorker-compose.yaml is returning a really strn=ange issue I can’t explain :
→ it is trying to change ownership of whole .snapshot folder (in my company context, every snaphot of every folders are stored here, this folder is protecter by WORM (write once read many) and cannot be chown obviously). But I’m totally lost about why it is doing that and from where it is getting the .snaphot (as /var/lib/mysql/ doesn’t exists on my local machine)

Attaching to npi360gen2-mysql
npi360gen2-mysql  | 2024-05-14 11:22:14+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/docker': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/docker/.env': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/docker/docker-compose.yaml': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/config': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/config/mysql8.cnf': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1400/database': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1600': Read-only file system
npi360gen2-mysql  | chown: changing ownership of '/var/lib/mysql/.snapshot/hourly.2024-05-13_1600/docker': Read-only file system

Thanks in advance for any ideas.