Say you want to quickly get started with Jenkins and “kick the tires” before fully committing to rolling out your own instance. How do you go about doing this?
Or say your company fully controls your Jenkins instance and they won’t give you the permissions to create your own pipeline and try out your build. It all has to go through them.
The second case is where I found myself. Good news is running Jenkins locally via docker just to test out your build file is super easy.
There are a couple guides that will walk you through this process. But in my case, my Jenkins file was starting a docker container itself — i.e. we would be running a docker image inside Jenkins docker image. That’s where things got tricky and I ended up making some changes to make that happen.
If you’re not sure what that means, look at the JenkinsFile below. As you can see the agent is a dockerfile.
sh 'npm run build'
sh 'npm run test_ci'
First pull the latest Jenkins image on docker:
docker image pull jenkins/jenkins:lts
Once that’s done, you can run the container using the following command:
docker run -u 0 --privileged
-v $(which docker):/usr/bin/docker
--name jenkins-local jenkins/jenkins:lts
There is a lot to unpack there so let’s have a look at the details:
- -p will forward the needed ports over to your local machine so you can access Jenkins in a browser
- the first -v will map the docker sock volume. You will need to do this if your JenkinsFile will start a docker image itself.
- the second -v will create a volume to store the Jenkin’s state
- — name will give a name to this container.
Run the command and check to make sure the container is running:
Now navigate to http://localhost:8082/ and you should be greeted with a Jenkins first time install page:
The easiest way to find the admin password is to do
docker logs [container_id] where
container_id is obtained from
And that should be all you’ll need to get your Jenkins up and running. The setup process is fairly straightforward so I won’t bore you with going over it. There are a lots of documentation available on it if need be.