This project focuses on a specific task: enabling Jenkins to communicate with the Docker engine while running inside a Docker container.
To run this project, you'll need the following requirements:
- Docker: You can download Docker from here.
- Docker Compose (Optional): It can be used to manage multiple Docker containers. Learn more about Docker Compose by visiting here.
In this guide, you will find the steps to launch Jenkins on Docker and establish communication between Docker and Jenkins.
-
Clone this repository locally or download it as a zip:
git clone https://github.com/veyselkaraca/jenkins-docker.git
-
Navigate to the project directory:
cd jenkins-docker
-
Build the Docker image for Jenkins using the provided Dockerfile:
docker build -t <image_name> .
Replace <image_name> with the image name of your jenkins.
- Or you can use docker compose for Jenkins image build
docker-compose build # or docker compose build
-
Run the Jenkins Docker container using the following command:
# docker engine docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home my-jenkins # or you can use docker compose docker-compose up -d # new verison of docker compose following this command docker compose up -d
This will start Jenkins in a Docker container and expose it on port 8080. You can access the Jenkins web interface by opening a web browser and going to http://localhost:8080.
-
To access the Jenkins container's shell, use the following command:
docker exec -it <container_id> /bin/bash
Replace <container_id> with the actual ID of the Jenkins container.
-
To access the docker socket in Jenkins container, use the following command:
docker info # or docker container ls
- Follow the initial setup wizard in the Jenkins web interface to set up Jenkins.
- When prompted for plugins, you can install the suggested plugins or select your preferred ones.
If you want to change the version of Docker Compose on Jenkins, open the Dockerfile file and update the curl request. For example:
RUN curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
To this
RUN curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
Now, you updated docker compose to version 1.25.4
- If you want to use Docker Compose for managing the Jenkins container and any additional services, you can update a docker-compose.yml file and define the services there. You can then start the services using docker-compose up.