Docker Compose Volume Mount Leading Whitespace Regex Error

  • Issue type: Volume mount CLI argument creates additional leading whitespace that causes regex error
  • OS Version/build: RHEL 9.6
  • App version: Docker Compose version v5.1.3
  • Steps to reproduce:

Code:

PARAM_MOUNT_POINTS="-v $(PROJECT)/production_sign:$(DOCKER_DIR)/production_sign"
$(DOCKER_COMPOSE_RUN) $(PARAM_MOUNT_POINTS) $(DOCKER_IMAGE) ./build.sh

Output:

Error response from daemon: create  /home/production_sign: " /home/production_sign" 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

Fix:
Remove space between -v and the folders to mount

PARAM_MOUNT_POINTS="-v$(PROJECT)/production_sign:$(DOCKER_DIR)/production_sign"

Is it running on a CI pipeline? $(PROJECT) is not a valid shell syntax if you are using it for variables. I don’t see how it is a Docker issue. It looks like the tools you are using generate invalid parameters. Docker has nothing to do with it probably.

Can you reproduce it with plain docker commands? instead of the build.sh and the special variable syntax in a local terminal?

I was only able to recreate the bug using a Makefile to set the PARAM_MOUNT_POINTS variable.

  • OS Version/build: RHEL 9.6 & Ubuntu 22.04

  • App version: Docker Compose version v5.1.3

  • Steps to reproduce:

  1. /home/jferguson3/Practice/production_sign/test.txt
  2. /home/jferguson3/Practice/Dockerfile
FROM ubuntu:22.04
  1. /home/jferguson3/Practice/compose.yaml
services:
  test-tools:
    image: test-tools:latest
    container_name: test-tools
    build:
      context: .
      network: 'host'
    user: "1000:1000"
    network_mode: 'host'
    stdin_open: true
    tty: true
    volumes:
      - /etc/localtime:/etc/localtime:ro
    working_dir: /app
  1. /home/jferguson3/Practice/Makefile
PARAM_MOUNT_POINTS="-v /home/jferguson3/Practice/production_sign:/home/production_sign"

test-build:
	docker compose -f compose.yaml build test-tools

test-run:
	docker compose -f compose.yaml run $(PARAM_MOUNT_POINTS) test-tools cat /home/production_sign/test.txt

Error & Workaround

So the problem is not Docker-related and not that you have a space, but that you quote the value of your variable in the Makefile.

The workaround helped only because when you start an argument with a single dash character like -v , only the first character will be interpreted as an argument key and the rest is the value. But when you have a space, the same happens and you will have that extra space in the value.

This should work in the first line of your Makefile

PARAM_MOUNT_POINTS=-v /home/jferguson3/Practice/production_sign:/home/production_sign

Then it will be interpreted as two arguments, not one.

Ah okay, that makes sense. I verified this fixes our issue.

This can be closed because it is not a docker bug. Thanks for your help!