简体   繁体   中英

Docker within Docker container not mapping .ssh volume

Im trying to map a volume from my main host machine, into a docker container, which then creates another docker container.

my first container is created as per the below:

docker run --rm -it \
-e JOB="release" \
-e LOG_FOLDER="$logDirectory" \
-v "$logDirectory":"$logDirectory" \
-e TEMP_FOLDER="$tempFolder" \
-v ~/.ssh:/root/.ssh \
-v "$tempFolder":"$tempFolder" \
-v /var/run/docker.sock:/var/run/docker.sock \
release

The above works great, and when I /bin/bash into this container I can see that the.ssh folder has mapped and is showing the contents from my host machine.

But then when I try to create ANOTHER docker container within this one, using the below:

docker run --rm -it \
-e JOB=summary \
-e TEMP_FOLDER="$TEMP_FOLDER" \
-v "$TEMP_FOLDER":"$TEMP_FOLDER" \
-v ~/.ssh:/root/.ssh \
-v /var/run/docker.sock:/var/run/docker.sock \
summary /bin/bash

The container is created with no issues, but the.ssh folder content hasn't been mapped. However the TEMP_FOLDER has been mapped correctly and is showing the content from the host machine, I dont know why the.ssh folder isn't doing the same?

Is there a permission problem?

Not sure why but the work around ive found is below, perhaps the root user was not the same across containers.

docker run --rm -it \
-e JOB="release" \
-e LOG_FOLDER="$logDirectory" \
-v "$logDirectory":"$logDirectory" \
-e TEMP_FOLDER="$tempFolder" \
-v ~/.ssh:/root/.ssh \
-v ~/.ssh:/home/user/.ssh \
-v /home/user/.ssh:/root/.ssh \
-v "$tempFolder":"$tempFolder" \
-v /var/run/docker.sock:/var/run/docker.sock \
release
docker run --rm -it \
-e JOB=summary \
-e TEMP_FOLDER="$TEMP_FOLDER" \
-v "$TEMP_FOLDER":"$TEMP_FOLDER" \
-v /home/user/.ssh:/root/.ssh \
-v /var/run/docker.sock:/var/run/docker.sock \
summary /bin/bash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM