Samuli Silvius | 747a8e2 | 2019-03-29 13:20:28 +0200 | [diff] [blame] | 1 | FROM quay.io/ansible/molecule:2.20 |
| 2 | |
| 3 | ARG USER_ID |
| 4 | ARG GROUP_ID |
| 5 | ARG DOCKER_GROUP_ID |
Mateusz Pilat | 86071d2 | 2019-04-17 12:19:10 +0200 | [diff] [blame] | 6 | ARG DOCKER_USER |
Samuli Silvius | 747a8e2 | 2019-03-29 13:20:28 +0200 | [diff] [blame] | 7 | |
| 8 | # When user/group provided, create user to have matching ids (for the host user) |
| 9 | # to avoid this docker writing files as root owned |
| 10 | RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \ |
| 11 | # shadow needed for addgroup |
| 12 | # sshpass needed for accessing docker_host (localhost) with ssh and without password prompt |
| 13 | apk --no-cache add shadow sshpass && \ |
Mateusz Pilat | 86071d2 | 2019-04-17 12:19:10 +0200 | [diff] [blame] | 14 | addgroup -g ${GROUP_ID} ${DOCKER_USER} && \ |
| 15 | adduser -D -u ${USER_ID} -G ${DOCKER_USER} ${DOCKER_USER} && \ |
Samuli Silvius | 747a8e2 | 2019-03-29 13:20:28 +0200 | [diff] [blame] | 16 | # Add user to same docker group as in docker_host to be able to use docker driver as sudo |
| 17 | groupadd docker-host -g ${DOCKER_GROUP_ID} && \ |
Mateusz Pilat | 86071d2 | 2019-04-17 12:19:10 +0200 | [diff] [blame] | 18 | usermod -aG ${DOCKER_GROUP_ID} ${DOCKER_USER} \ |
Samuli Silvius | 747a8e2 | 2019-03-29 13:20:28 +0200 | [diff] [blame] | 19 | ;fi |
| 20 | |
Mateusz Pilat | 86071d2 | 2019-04-17 12:19:10 +0200 | [diff] [blame] | 21 | USER ${DOCKER_USER} |
| 22 | |