Installing docker on ubuntu 20
$ sudo apt update
$ sudo apt install docker.io
* This method installs from official ubuntu repositories
Verify the installed version
$ docker --version
Enable docker on system reboot
$ sudo systemctl enable --now docker
Login to docker registry
$ sudo docker login
Verify docker run
$ docker run hello-world
Basic docker commands
List docker information
$ docker info
List docker images
$ docker images
List docker containers
$ docker ps
Kill a container
$ docker kill <container-name>
Start a non-running container
$ docker start <container-name>
Stop a container
$ docker stop <container-name>
Docker volumes
Docker volumes are used by docker containers for persisting data. Volumes are completely managed by docker itself and are easier to backup, share and it works on any platform.
Create a docker volume
$ docker volume create <volume name>
List available docker volumes
$ docker volume ls
Inspect a docker volume
$ docker volume inspect <volume name>
Running Jenkins on docker
Pull the official jenkins LTS docker image
$ docker pull jenkins/jenkins:lts
for a lighter image size use alpine-based image
$ docker pull jenkins/jenkins:lts-alpine
Run the jenkins image with a mounted volume and as a name container for configuration persistence
$ docker run -d -p 8080:8080 -v jenkins-dev:/var/jenikins_home --name jenkins-dev jenkins/jenkins:lts-alpine
* here "jenkins-dev" is given name to both the newly created docker
volume and the jenkins container
Verify if the container is running successfully at http://<hostname>:8080
During the first run Jenkins would require an administrator password, this can be found at /var/jenkins_home/secrets/initialAdminPassword and can be fetched through this command -
$ docker exec <container-name> cat /var/jenkins_home/secrets/initialAdminPassword