How to run Jenkins from a Docker Container

(Linux Operating System)

Installation

Install Docker

Create Directory

Build docker image and run

docker run
  -u root
  --rm
  -d
  -p 8080:8080
  -p 50000:50000
  -v ~/Docker/Jenkins:/var/jenkins_home
  -v /var/run/docker.sock:/var/run/docker.sock
  --name jenkins 
  jenkinsci/blueocean
docker run -u root --rm -d -p 8080:8080 -p 50000:50000 -v ~/Docker/Jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jenkinsci/blueocean

Jenkins configuration

Starting Jenkins



Interacting with Container

Running created container

docker container start jenkins

Listing running container

docker container ls --all
docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
42e3edd6087b        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   12 minutes ago      Up 12 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins

Stop container

docker container stop jenkins

Remove container

docker container rm jenkins

Remove image

docker image rm jenkinsci/blueocean


Bulk removing images and containers:

#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)


Sources