docker network create jenkins \ &&
docker run \
--name jenkins-docker \ # ( Optional ) Specifies the Docker container name to use for running the image. By default, Docker generates a unique name for the container.
--rm \ # ( Optional ) Automatically removes the Docker container (the instance of the Docker image) when it is shut down.
--detach \ # ( Optional ) Runs the Docker container in the background. You can stop this instance by running docker stop jenkins-docker.
--privileged \ # Running Docker in Docker currently requires privileged access to function properly. This requirement may be relaxed with newer Linux kernel versions.
--network jenkins \ # This corresponds with the network created in the earlier step.
--network-alias docker \ # Makes the Docker in Docker container available as the hostname docker within the jenkins network.
--env DOCKER_TLS_CERTDIR=/certs \ # Enables the use of TLS in the Docker server. Due to the use of a privileged container, this is recommended, though it requires the use of the shared volume described below. This environment variable controls the root directory where Docker TLS certificates are managed.
--volume jenkins-docker-certs:/certs/client \ # Maps the /certs/client directory inside the container to a Docker volume named jenkins-docker-certs as created above.
--volume jenkins-data:/var/jenkins_home \ # Maps the /var/jenkins_home directory inside the container to the Docker volume named jenkins-data. This allows for other Docker containers controlled by this Docker container’s Docker daemon to mount data from Jenkins.
--publish 2376:2376 \ # ( Optional ) Exposes the Docker daemon port on the host machine. This is useful for executing docker commands on the host machine to control this inner Docker daemon.
docker:dind \ # The docker:dind image itself. Download this image before running, by using the command: docker image pull docker:dind.
--storage-driver overlay2 # The storage driver for the Docker volume. Refer to the Docker storage drivers documentation for supported options.