docker-compose volume on gcp are rewritting name depending on user

64 Views Asked by At

I am using a startup script on gcp that launches a docker compose file at instance startup.

The issue is coming from docker-compose that does not launch same volume name if I start it as jeorfevre or if I start them as gcp user (start script). It seems that the volume names are rewritten - how can I fix the volume names used in docker compose regardless of user launching them?

I want to launch always jeorfevre_mariadb_data, but he tries to launch _mariadb_data instead.

Thanks for help.

GCP Startup script :

echo " --------------------- STARTUP SCRIPT ---------------------------"
echo "  - chechup "

docker version
docker volume ls

curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/suitecrm/docker-compose.yml > docker-compose.yml

echo "  - Current user $USER"
sudo docker compose up -d
echo " -----------      END       -----------"

Docker-compose file

version: '2'
services:
  mariadb:
    image: docker.io/bitnami/mariadb:10.6
    environment:
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_USER=bn_suitecrm
      - MARIADB_DATABASE=bitnami_suitecrm
      - MARIADB_PASSWORD=bitnami123
    volumes:
      - 'mariadb_data:/bitnami/mariadb'
  suitecrm:
    image: docker.io/bitnami/suitecrm:8
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - SUITECRM_DATABASE_HOST=mariadb
      - SUITECRM_DATABASE_PORT_NUMBER=3306
      - SUITECRM_DATABASE_USER=bn_suitecrm
      - SUITECRM_DATABASE_NAME=bitnami_suitecrm
      - SUITECRM_DATABASE_PASSWORD=bitnami123
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - 'suitecrm_data:/bitnami/suitecrm'
    depends_on:
      - mariadb
volumes:
  mariadb_data:
    driver: local
  suitecrm_data:
    driver: local

GCP log :

  Mar 22 09:16:30 crm2-vm google_metadata_script_runner[1094]: startup-script:  --------------------- STARTUP SCRIPT ---------------------------
Mar 22 09:16:30 crm2-vm google_metadata_script_runner[1094]: startup-script:   - chechup
Ubuntu 20.04.6 LTS crm2-vm ttyS0

crm2-vm login: Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script: Client: Docker Engine - Community
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Version:           23.0.1
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  API version:       1.42
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Go version:        go1.19.5
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Git commit:        a5ee5b1
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Built:             Thu Feb  9 19:46:56 2023
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  OS/Arch:           linux/amd64
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Context:           default
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script: Server: Docker Engine - Community
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  Engine:
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Version:          23.0.1
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   API version:      1.42 (minimum version 1.12)
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Go version:       go1.19.5
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Git commit:       bc3805a
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Built:            Thu Feb  9 19:46:56 2023
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   OS/Arch:          linux/amd64
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Experimental:     false
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  containerd:
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Version:          1.6.18
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  runc:
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Version:          1.1.4
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   GitCommit:        v1.1.4-0-g5fd4c4d
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:  docker-init:
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   Version:          0.19.0
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   GitCommit:        de40ad0
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script: DRIVER    VOLUME NAME
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script: local     jeorfevre_mariadb_data
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script: local     jeorfevre_suitecrm_data
Mar 22 09:16:31 crm2-vm google_metadata_script_runner[1094]: startup-script:   - Current user
Mar 22 09:16:32 crm2-vm google_metadata_script_runner[1094]: startup-script:  Volume "_mariadb_data"  Creating
Mar 22 09:16:32 crm2-vm google_metadata_script_runner[1094]: startup-script:  Volume "_mariadb_data"  Error
Mar 22 09:16:32 crm2-vm google_metadata_script_runner[1094]: startup-script: Error response from daemon: create _mariadb_data: "_mariadb_data" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path
Mar 22 09:16:32 crm2-vm google_metadata_script_runner[1094]: startup-script:  -----------      END       -----------
1

There are 1 best solutions below

0
On

Indead, I've found the solution and share it with the community.

You have to set the directory name in order to set the right VOLUME NAME of "compose -p" :

sudo docker compose -p jeorfevre up  -d 

https://forums.docker.com/t/docker-compose-prepends-directory-name-to-named-volumes/32835