blob: 5c2343c9212f1d88485da498217f76c7298a6074 [file] [log] [blame]
Samuli Silvius747a8e22019-03-29 13:20:28 +02001FROM quay.io/ansible/molecule:2.20
2
3ARG USER_ID
4ARG GROUP_ID
5ARG DOCKER_GROUP_ID
Mateusz Pilat86071d22019-04-17 12:19:10 +02006ARG DOCKER_USER
Samuli Silvius747a8e22019-03-29 13:20:28 +02007
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
10RUN 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 Pilat86071d22019-04-17 12:19:10 +020014 addgroup -g ${GROUP_ID} ${DOCKER_USER} && \
15 adduser -D -u ${USER_ID} -G ${DOCKER_USER} ${DOCKER_USER} && \
Samuli Silvius747a8e22019-03-29 13:20:28 +020016 # Add user to same docker group as in docker_host to be able to use docker driver as sudo
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020017 groupadd docker-host -f -g ${DOCKER_GROUP_ID} && \
Mateusz Pilat86071d22019-04-17 12:19:10 +020018 usermod -aG ${DOCKER_GROUP_ID} ${DOCKER_USER} \
Samuli Silvius747a8e22019-03-29 13:20:28 +020019;fi
20
Mateusz Pilat86071d22019-04-17 12:19:10 +020021USER ${DOCKER_USER}
22