Skip to content

Instantly share code, notes, and snippets.

@yanli0303
Created July 14, 2023 16:14
Show Gist options
  • Save yanli0303/7bf4b39645d1c9617202f7945ade400a to your computer and use it in GitHub Desktop.
Save yanli0303/7bf4b39645d1c9617202f7945ade400a to your computer and use it in GitHub Desktop.
Set up Jenkins server with Docker

Set up Jenkins server with Docker

Refer to https://www.jenkins.io/doc/book/installing/docker/

Step 1 Allow docker jobs in Jenkins

docker run \
  --name docker-in-jenkins \
  --rm \
  --detach \
  --privileged \
  --network jenkins \
  --network-alias docker \
  --env DOCKER_TLS_CERTDIR=/certs \
  --volume jenkins-docker-certs:/certs/client \
  --volume docker-in-jenkins-data:/var/jenkins_home \
  --publish 2376:2376 \
  docker:dind \
  --storage-driver overlay2

To stop: docker stop docker-in-jenkins

Step 2 Run Jenkins

docker run \
  --name jenkins-lts \
  --restart=on-failure \
  --detach \
  --network jenkins \
  --env DOCKER_HOST=tcp://docker:2376 \
  --env DOCKER_CERT_PATH=/certs/client \
  --env DOCKER_TLS_VERIFY=1 \
  --publish 8080:8080 \
  --publish 50000:50000 \
  --volume jenkins-data:/var/jenkins_home \
  --volume jenkins-docker-certs:/certs/client:ro \
  jenkins/jenkins:lts-jdk11

Later to start it: docker container start jenkins-lts. To stop: docker stop jenkins-lts

Step 3 prevent user processes to be killed once the user session completed

Refer to https://github.com/containers/podman/blob/b03466c/troubleshooting.md#17-rootless-containers-exit-once-the-user-session-exits

# loginctl enable-linger $UID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment