Since Jenkins now relies on Docker, we must install Docker on this Jenkins server:
jenkins@ci:$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
jenkins@ci:$ sudo add-apt-repository "deb [arch=amd64] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable"
jenkins@ci:$ sudo apt update
jenkins@ci:$ sudo apt install -y docker-ce
This installation will do a few things, as follows:
- Install the Docker Engine, which runs as a daemon in the background
- Install the Docker client, which is a command-line tool (docker) we can run in our Terminal
- Create a user on our machine called docker, and assign it to the docker group
To check Docker is installed properly, you can check its status by runningĀ sudo systemctl status docker.
By default, the docker command must be invoked with root privileges. The exception to this rule is if the user is docker, or if the user is in the docker group. We are running our Jenkins server under the user jenkins; therefore, to allow our Jenkins server to spawn new Docker containers, we must add the jenkins user to the docker group:
jenkins@ci:$ sudo usermod -aG docker jenkins
To check that this is successful, run the following:
jenkins@ci:$ grep docker /etc/group
docker:x:999:jenkins
Lastly, restart the Jenkins service for this change to take effect:
jenkins@ci:$ sudo systemctl restart jenkins