Docker in Docker cannot mount volume

前端 未结 10 1838
情话喂你
情话喂你 2020-11-29 21:09

I am running a Jenkins cluster where in the Master and Slave, both are running as a Docker containers.

The Host is latest boot2docker VM running on MacOS.

T

10条回答
  •  萌比男神i
    2020-11-29 21:34

    You can solve this passing in an environment variable. Example:

    .
    ├── docker-compose.yml
    └── my-volume-dir
        └── test.txt
    

    In docker-compose.yml

    version: "3.3"
    services:
      test:
        image: "ubuntu:20.04"
        volumes:
          - ${REPO_ROOT-.}/my-volume-dir:/my-volume
        entrypoint: ls /my-volume
    

    To test run

    docker run -e REPO_ROOT=${PWD} \
       -v /var/run/docker.sock:/var/run/docker.sock \
       -v ${PWD}:/my-repo \
       -w /my-repo \
       docker/compose \
       docker-compose up test
    

    You should see in the output:

    test_1  | test.txt
    

提交回复
热议问题