[compose.yml] [volumes] target property not parse

+ cat compose.yml
services:
    test:
        image: scratch
        volumes:
            - type: bind
              source: ~/bin
              target: ~/bin
              read_only: true

Now a little attention

+ docker compose config | grep /bin
        source: /home/USER/bin
        target: ~/bin

But, as last line, I expected

        target: /home/USER/bin

Explanation?

The source is on the current node, so compose can expand the ~ to the full home path.

The target is inside the (to be run) container, compose doesn’t know what user is going to be used inside, so it keeps the ~ in place.

1 Like

Thanks.

But

+ cat compose.yml
services:
    test:
        extends:
            file: ~/xxx
            service: xxx
+ docker compose config
cannot read ~/xxx

Why, also in this case, the tilde is not interpolated (/home/USER/xxx)?

OS variables are expanded. You can then use ${HOME}

1 Like

mmmhhh… but I would like the expansion to be done inside the container

├── 1.yml
├── 2.yml
└── Dockerfile



+ cat 1.yml
services:
    test:
        build: .
        volumes:
            - type: bind
              source: ~/bin
              target: /home/internal-user/bin
              read_only: true
        command: sh -c "ls -d ~/bin"



+ cat 2.yml
services:
    test:
        build: .
        volumes:
            - type: bind
              source: ~/bin
              target: ~/bin
              read_only: true
        command: sh -c "ls -d ~/bin"



+ cat Dockerfile
FROM ubuntu:latest
RUN apt-get update \
&& apt-get -y install gettext-base \
&& groupadd \
    -g 1234 \
    internal-user \
&& useradd \
    -m \
    -s /bin/bash \
    -u 1234 \
    -g internal-user \
    internal-user
USER internal-user:internal-user

Let’s do some tests

+ docker compose --file 1.yml run --rm test
/home/internal-user/bin

OK

+ docker compose --file 2.yml run --rm test
Error response from daemon: invalid mount config for type "bind": invalid mount path: '~/bin' mount path must be absolute

Any solutions?

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.