Install Jenkins Using Docker23 Dec 2020 | Jenkins
To get the start, you need to install Jenkins. There are plenty of ways you can achieve this goal. You can build from source code, run war file in Java, or run from a Docker image. etc.
Generally, Jenkins provides two major releases, weekly and lts. Weekly, as the name says, new releases are produced weekly to deliver bug fixes and features to users and plugin developers. lts, every 12 weeks from the stream of regular releases as the stable release for that time period.
Here, I am gonna illustrate that install Jenkins using Docker. If you run Jenkins using Docker, you have to fit these prerequisites:
- A256 MB of RAM
- 1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)
The next step, create a
docker-compose.yaml file. And place your instructions into it.
version: '3.9' services: jenkins: image: jenkins/jenkins:
ltsports: - 8080:8080 - 50000:50000 volumes: - ./jenkins_home:/var/jenkins_home/ restart: always privileged: true user: root
The above docker-compose file grants its admin permission by
privileged: true and
user: root. And mounting
Jenkins folder to
/var/jenkins_home inside the container’s instance. Take a loot at Official Jenkins Docker image for more details.
Navigate to the same folder where you place the docker-compose.yaml file. Then expose your application up.
$ docker-compose up -d
You can also use docker command directly.
docker run \ -v $(pwd)/jenkins_home:/var/jenkins_home \ -d \ -p 8080:8080 \ -p 50000:50000 \ -u root \ jenkins/jenkins:lts
NOTE: The above command probably will run your Jenkins web application on a private network. If you can't access your Jenkins remotely(such as: running on a VPS), you can add
--net hostto use the
hostnetwork instead of using the default
bridge. You can run
docker network listto list all of available network objects on your machine.
Docker compose with
host network mode:
version: '3.9' services: jenkins: image: jenkins/jenkins:lts volumes: - ./jenkins_home:/var/jenkins_home/ restart: always privileged: true user: root
Or using docker command directly.
docker run \ -v $(pwd)/jenkins_home:/var/jenkins_home \ -d \ -u root \
--net host\ jenkins/jenkins:lts
You will see someting like this for setup wizard.
check your initial admin password
$ docker exec <containerid> cat /var/jenkins_home/secrets/initialAdminPassword
Add first admin user
Now, a Jenkins instance is fully set up. And in the next articles, I will discuss how to use the Jenkins dashboard.