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 |
| 6 | |
| 7 | # When user/group provided, create user to have matching ids (for the host user) |
| 8 | # to avoid this docker writing files as root owned |
| 9 | RUN if [ ${USER_ID:-0} -ne 0 ] && [ ${GROUP_ID:-0} -ne 0 ]; then \ |
| 10 | # shadow needed for addgroup |
| 11 | # sshpass needed for accessing docker_host (localhost) with ssh and without password prompt |
| 12 | apk --no-cache add shadow sshpass && \ |
| 13 | addgroup -g ${GROUP_ID} molecule && \ |
| 14 | adduser -D -u ${USER_ID} -G molecule molecule && \ |
| 15 | # Add user to same docker group as in docker_host to be able to use docker driver as sudo |
| 16 | groupadd docker-host -g ${DOCKER_GROUP_ID} && \ |
| 17 | usermod -aG ${DOCKER_GROUP_ID} molecule \ |
| 18 | ;fi |
| 19 | |
| 20 | USER molecule |