Run the Jenkins Container
Docker simplifies packaging applications with all their dependencies.
Through Docker, we can have a running Jenkins instance in a matter of seconds.
In your terminal, first build a jenkins image with docker installed. Create a Dockerfile
with the following:
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io
EXPOSE 8080
From the same directory as your Dockerfile, build the image:
docker build -t jenkins:lts-docker .
Running Jenkins as a docker container on a BAH managed machine requires specific certificates and tooling to be installed. A Dockerfile meeting these requirements can be built from the solutions-delivery-platform/bah-jenkins repo. |
Then, to start jenkins, run:
(If running Docker for Windows, please refer to Important section below)
docker run --name jenkins \
-v /var/run/docker.sock:/var/run/docker.sock \
--privileged \
--user root \
-p 50000:50000 \
-p 8080:8080 \
-d \
jenkins:lts-docker
Command Section | Description |
---|---|
docker run |
Tells docker to going to run a container image |
--name jenkins |
Names the container being launched |
-v /var/run/docker.sock:/var/run/docker.sock |
Mounts the local docker daemon socket to the Jenkins container. |
–privileged |
Escalates the container permissions so it can launch containers on the host docker daemon |
–user root |
Runs the container as the root user so it can launch containers on the host docker daemon |
-p 50000:50000 |
Port forwarding of the default JNLP agent port to our localhost |
-p 8080:8080 |
Port forwading of the Jenkins Console port to our localhost |
-d |
Runs the container process in the background |
jenkins:lts-docker |
The container image from which to run this container |
If port 8080 is already in use by another process then this command will fail. To run Jenkins on a different port, swap out the first 8080 to your desired port: |
Windows OS: When using Docker for Windows, use the following command to run the Jenkins container:
You can run |
You can validate the container launched as expected by going to http://localhost:8080
.
You should see the Jenkins Startup Wizard:
In the next section, we’ll learn how to get past this Startup Wizard and configure the newly deployed Jenkins instance.