# Allow docker to be mounted and executed in a docker container
FROM jenkins/jenkins:lts

# The docker group gid on the host
ARG docker_gid
# The URL from which get the docker package
ARG docker_deb_url

# We will be root for all of the installation process
USER root

# Creating a docker group to the same gid as the host, adding jenkins to it
RUN groupadd -g ${docker_gid} dockerhost && gpasswd -a jenkins dockerhost

RUN wget ${docker_deb_url} --output-document=/docker.deb
RUN apt-get update \
	&& (dpkg -i /docker.deb || (apt-get install -fy && dpkg -i /docker.deb)) \
	&& rm /docker.deb \
	&& rm -rf /var/lib/apt/lists/*

# Going back to user jenkins
USER jenkins
