Run Jenkins controller and agent with Go environment in Docker Compose
Recently, I’ve been spending some time learning about Jenkins and building CI/CD pipelines. I needed a quick and easy solution to deploy a Jenkins controller and agent instance.
Luckily, running Jenkins in Docker is quite straightforward.
- The first step is installing docker and docker-compose on your host machine. As this is distro and OS-specific, a quick Google search should help.
- Once you have both available, create 2 directories which will hold Jenkins data on your host and serve as Docker volumes:
mkdir -p ~/{jenkins,jnlp_agent}
- Start a Jenkins container in Docker:
docker run -d \
-u root \
— name=jenkins \
-e TZ=America/New_York \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-v $HOME/jenkins:/var/jenkins_home \
-p 8080:8080 \
-p 50000:50000 \
jenkins/jenkins:lts
4. Navigate your browser to the Jenkins container’s URL (https://localhost:8080 if Docker is running on the same machine)
5. Jenkins will ask for the unlock password, either look for the code on your host’s shared volume or enter the container with docker exec -it jenkins /bin/bash
6. Follow the on-screen instructions to finish the initial setup for Jenkins, set up a user, install the default plugins, set your hostname/ip, etc.
7. Time to add a Jenkins agent! There are official jenkins/inbound-agent
Docker images available on Dockerhub, but I needed a Go build environment on the agent. You can build a custom Docker image to add a Go environment but there is an even easier solution! We can run a jenkinsciinfra/inbound-agent-golang
container.
8. Before starting the Jenkins agent, we need to set up the node connection on the Jenkins agent. To do that, navigate to Jenkins > Manage Jenkins > Manage Nodes > New Node.
On the node configuration page we can set the following:
Add a Node name (jenkins_agent_golang for example), choose Permanent agent / copy existing node

Set the executors to 1
Set the remote root path: /var/jenkins_home
Leave defaults for the rest of options, and save the configuration.

Select the new node from nodes list to get the Java launch command with the secret hash:

Make a note of the ‘secret’ (don’t use mine from the screenshot, yours will be different).
9. Run the agent: docker run jenkins/jnlp-agent-golang -url http://YOURIP:8080 <secret> <jenkins_agent's name>
10. The node should appear online in Jenkins now in the left side menu, under Build executor status.
11. Use docker ps
to show the running containers and stop the agent container, then log out of Jenkins and stop that container.
12. Now all that’s left to write a docker-compose.yml
so we can bring up the entire environment with just one docker compose up -d
command!
Here’s an example that should work.
jenkins_controller:
image: jenkins/jenkins:lts
container_name: jenkins
user: root
environment:
— TZ=America/Denver
restart: always
volumes:
— /var/run/docker.sock:/var/run/docker.sock
— /usr/bin/docker:/usr/bin/docker
— $HOME/jenkins:/var/jenkins_home
ports:
— 8080:8080
— 50000:50000
jenkins_agent_golang:
image: jenkinsciinfra/inbound-agent-golang
container_name: jenkins-agent-golang
user: root
command: -url http://YOURIP:8080 <secret> jenkins-slave-golang
restart: always
volumes:
— /var/run/docker.sock:/var/run/docker.sock
— /usr/bin/docker:/usr/bin/docker
— $HOME/jnlp_agent:/var/jenkins_home
13. Run docker compose up -d
to launch the environment.
From here on out, you can set up a Pipeline in Jenkins, add a Github repo with your source code, and start building a project pipeline script. I’m planning cover those steps in an upcoming article.