This tutorial explains, how to install docker on EC2 Instance. Before starting, let’s have some brief knowledge about Docker.
Docker is a platform that combines applications and its dependencies in the form of packages, called container. We can run multiple containers on a single Operating System. Containers are not Virtual Machines. Virtual Machines requires Operating System to run applications, but containers do not. As containers don’t need an Operating System, it takes very little time to start and hence it is very faster than Virtual Machines.
- Sep 17, 2021 Install jenkins in a docker container on ubuntu. GitHub Gist: instantly share code, notes, and snippets.
- Install JDK on Ubuntu. Download and Install Oracle Java 8 on Ubuntu 18.04/16.04 LTS. Step 1: Add Jenkins APT Repository Key. Output: Step 2: Install Jenkins On Ubuntu. Step 4: Start Jenkins Service. Output: Step 5: Add Firewall Rule. Step 6: Configure Jenkins.
- Install Docker Compose on RHEL 8 / CentOS 8. Follow our separate guide on installation of latest Docker Compose on Linux. Install Docker Compose on Linux. For the sake of keeping this guide brief, we won’t dive into Docker compose usage. I’ll recommend you go through Official Docker documentation and Docker Compose documentation to learn more.
- This is very similar to the technique described by Pini Reznik in Continuous Delivery with Docker on Mesos In Less than a Minute, but we're going to use sudo to avoid the issues Pini faced with adding the user to the Docker group. We'll be using the official Jenkins image as a base, which makes everything pretty straightforward.
Install Jenkins on WSL-Ubuntu. Docker image may the right choice, but in Windows OS you can not install docker and other virtual machine solution at the same time, so I want to try if WSL.
Also Learn: How to install Ansible on Amazon Linux(EC2 )
and Launching Amazon Linux EC2 Instance
We're going through the steps to install Jenkins using Docker-Compose. Install Docker Compose Docker Desktop for Mac and Docker Toolbox already include Compose along with other Docker apps, so Mac users do not need to install Compose separately.
Let’s Install Docker on EC2 Instance
In this tutorial, we will use Amazon Linux to install docker. Amazon Linux/Amazon Linux2 is the Linux Operating System used in EC2 Instance.
Step 1– Log to Linux EC2 Instance and update it.
$ sudo yum update -y
Step 2– Install docker using Yum command
$ sudo yum install docker -y
Step 3– Start Docker Service
$ Service docker start
Step 4– Check docker Version.
$ docker -v
Basic Configuration (Creating Docker File / Running Docker Image)
After you install docker on ec2 , let’s have some basic setup for Docker.
Step 1 – Create a docker file
Dockerfile is a text file where we write instructions to build an image.
Create a folder name Images on the Amazon Linux box.
$ mkdir images
Install Jenkins With Docker Compose
Move to folder images
$ cd images
Create a file name Dockerfile inside images folder
$ nano Dockerfile
Put the content in the following way inside the Dockerfile.
FROM Ubuntu ( It will use the Official image Ubuntu to build your image)
MAINTAINER chandan <[email protected]>
( It sets the Author field of the generated image)
RUN apt-get update ( It will update the image at the time of Build)
CMD [ “echo”, ” Hello World ……….! “] ( It will run echo command when we run the docker container image)
Please also readHow to install docker on ec2 Instance(Windows)
You may also likeInstall Docker on Ubuntu using Script
Step 2– Run the docker build command to build the image.
$ docker build .
Note : ( . command is used when you are inside images folder where Dockerfile is present, alternatively you can put the docker file absolute path like /home/ec2-user/images/Dockerfile)
You can run the following command as well to Name and tag your Image. Here myimage is the Name and 01 is Tag of the image.
$ docker build -t myimage:01 .
Step 3– See the Docker Images after build
$ docker images
Step 4 – Run the docker image
$ docker run 07deaa33585e
Here 07deaa33585e is the IMAGE ID that can be seen in docker images command.
You can see here, it executed the echo command as soon as we run the docker image. In the same way, we can run any script, commands or any application by running a docker image.
Install Jenkins Using Docker Compose
Click to tweet this tip !
I hope you enjoyed this tutorial and learned to install docker on ec2 instance (Amazon Linux). If you think this is really helpful, please do share this with others as well. Please also share your valuable feedback, comment or any query in the comment box. I will really happy to resolve your all queries anytime.
If you think we helped you or just want to support us, please consider these:-
Connect to us: FacebookTwitter
This plugin allows containers to be dynamically provisioned as Jenkins nodes using Docker. It is a Jenkins Cloud plugin for Docker.
The aim of this docker plugin is to be able to use a Docker host to dynamically provision a docker container as a Jenkins agent node, let that run a single build, then tear-down that node, without the build process (or Jenkins job definition) requiring any awareness of docker.
The Jenkins administrator configures Jenkins with knowledge of one or more docker hosts (or swarms), knowledge of one or more 'templates' (which describe the labels/tags that this template provides, the docker image, how to start it, etc) and Jenkins can then run docker containers to provide Jenkins (agent) Nodes on which Jenkins can run builds.
- Support and contribution guide
Note: There is more than one docker plugin for Jenkins. While this can be confusing for end-users, it's even more confusing when end users report bugs in the wrong place. e.g. if you are using Jenkins pipeline / workflow / Jenkinsfile builds with code including terms like
docker.image etc then you're using the
docker-workflow plugin and should go to its repository instead of this one.
Note: This plugin does not provide a Docker daemon; it allows Jenkins to use a docker daemon. i.e. Once you've installed docker on your OS, this plugin will allow Jenkins to use it.
A quick setup is :
- get a docker environment running
- follow the instructions for creating a docker image that can be used as a Jenkins Agent
Follow the installation steps on the docker website.
If your Jenkins instance is not on the same OS as the docker install, you will need to open the docker TCP port so that Jenkins can communicate with the docker daemon. This can be achieved by editing the docker config file and setting (for example)
The docker configuration file location will depend your system, but it is likely to be
Multiple Docker Hosts
If you want to use more than just one physical node to run containers, you can use Docker Swarm Standalone or you can define more than one docker 'cloud'. The docker engine swarm mode API is not supported (at present; enhancement contributions would be welcomed).
To use the standalone swarm, follow docker swarm standalone instructions and configure Jenkins with the swarm's API endpoint.
Docker plugin is a 'Cloud' implementation. You'll need to edit Jenkins system configuration (Jenkins -> Manage -> System configuration) and add a new Cloud of type 'Docker'.
Configure Docker (or Swarm standalone) API URL with required credentials. The test button lets you check the connection.
Then configure Agent templates, assigning them labels that you can use so your jobs select the appropriate template, and set the docker container to be run with whatever container settings you require.
Creating a docker image
Install Jenkins Using Docker
You need a docker image that can be used to run Jenkins agent runtime. Depending on the launch method you select, there's some prerequisites for the Docker image to be used:
Launch via SSH
- sshd server and a JDK installed. You can use jenkins/ssh-agent as a basis for a custom image.
- a SSH key (based on unique Jenkins master instance identity) can be injected in container on startup, you don't need any credential set as long as you use standard openssl sshd.
For backward compatibility or non-standard sshd packaged in your docker image, you also have option to provide manually configured ssh credentials
- Note: If the docker container's host SSH key is not trusted by Jenkins (usually the case) then you'll need to set the SSH host key verification method to 'non-verifying'.
Launch via JNLP
Setup Jenkins With Docker Compose
- a JDK installed. You can use jenkins/inbound-agent as a basis for a custom image.
- Jenkins master URL has to be reachable from container.
- container will be configured automatically with agent's name and secret, so you don't need any special configuration of the container.
- a JDK installed. You can use jenkins/agent as a basis for a custom image.
To create a custom image and bundle your favorite tools, create a
Dockerfile with the
FROM to point to one of the jenkins/*-agent reference images, and install everything needed for your own usage, e.g.
Install Jenkins Using Docker Ubuntu
Note on ENTRYPOINT
Avoid overriding the docker command, as the SSH Launcher relies on it.
You can use an Entrypoint to run some side service inside your build agent container before the agent runtime starts and establish a connection ... but you MUST ensure your entrypoint eventually runs the passed command:
More information can be obtained from the online help built into the Jenkins WebUI. Most configurable fields have explanatory text. This, combined with knowledge of docker itself, should answer most questions.
Jenkins can be configured using Groovy code, and the docker plugin is no exception. For example, this configuration script could be run automatically upon Jenkins post-initialization or through the Jenkins script console. If run, this script will configure the docker-plugin to look for a docker daemon running within the same OS as the Jenkins master (connecting to Docker service through
unix:///var/run/docker.sock) and with the containers connecting to Jenkins using the 'attach' method.
When faced with repetitive technical tasks, finding automation solutions that work can be a chore. With Jenkins, an open-source automation server, you can efficiently manage tasks from building to deploying software. Jenkins is Java-based, installed from Ubuntu packages or by downloading and running its web application archive (WAR) file — a collection of files that make up a complete web application to run on a server.
In this tutorial we’ll install Jenkins on Ubuntu 20.04, start the development server and create an administrative user to get you started in exploring what Jenkins can do. While you’ll have a development-level server ready for use at the conclusion of this tutorial, to secure this installation for production, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 18.04.
To follow this tutorial, you will need:
- One Ubuntu 20.04 server configured with a non-root sudo user and firewall by following the Ubuntu 20.04 initial server setup guide. We recommend starting with at least 1 GB of RAM. Visit Jenkins’s “Hardware Recommendations” for guidance in planning the capacity of a production-level Jenkins installation.
- Oracle JDK 11 installed, following our guidelines on installing specific versions of OpenJDK on Ubuntu 20.04.
Step 1 — Installing Jenkins
The version of Jenkins included with the default Ubuntu packages is often behind the latest available version from the project itself. To ensure you have the latest fixes and features, use the project-maintained packages to install Jenkins.
First, add the repository key to the system:
After the key is added the system will return with
Install Jenkins On Docker Ubuntu
Next, let’s append the Debian package repository address to the server’s
After both commands have been entered, we’ll run
update so that
apt will use the new repository.
Finally, we’ll install Jenkins and its dependencies.
Now that Jenkins and its dependencies are in place, we’ll start the Jenkins server.
Step 2 — Starting Jenkins
Let’s start Jenkins by using
systemctl doesn’t display status output, we’ll use the
status command to verify that Jenkins started successfully:
If everything went well, the beginning of the status output shows that the service is active and configured to start at boot:
Now that Jenkins is up and running, let’s adjust our firewall rules so that we can reach it from a web browser to complete the initial setup.
Step 3 — Opening the Firewall
To set up a UFW firewall, visit Initial Server Setup with Ubuntu 20.04, Step 4- Setting up a Basic Firewall. By default, Jenkins runs on port
8080. We’ll open that port using
Note: If the firewall is inactive, the following commands will allow OpenSSH and enable the firewall:
ufw’s status to confirm the new rules:
You’ll notice that traffic is allowed to port
8080 from anywhere:
With Jenkins installed and our firewall configured, we can complete the installation stage and dive into Jenkins setup.
Step 4 — Setting Up Jenkins
Docker Ubuntu Image
To set up your installation, visit Jenkins on its default port,
8080, using your server domain name or IP address:
You should receive the Unlock Jenkins screen, which displays the location of the initial password:
In the terminal window, use the
cat command to display the password:
Copy the 32-character alphanumeric password from the terminal and paste it into the Administrator password field, then click Continue.
The next screen presents the option of installing suggested plugins or selecting specific plugins:
We’ll click the Install suggested plugins option, which will immediately begin the installation process.
When the installation is complete, you’ll be prompted to set up the first administrative user. It’s possible to skip this step and continue as
admin using the initial password we used above, but we’ll take a moment to create the user.
Note: The default Jenkins server is NOT encrypted, so the data submitted with this form is not protected. Refer to How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 20.04 to protect user credentials and information about builds that are transmitted via the web interface.
Enter the name and password for your user:
You’ll receive an Instance Configuration page that will ask you to confirm the preferred URL for your Jenkins instance. Confirm either the domain name for your server or your server’s IP address:
After confirming the appropriate information, click Save and Finish. You’ll receive a confirmation page confirming that “Jenkins is Ready!”:
Click Start using Jenkins to visit the main Jenkins dashboard:
At this point, you have completed a successful installation of Jenkins.
In this tutorial, you installed Jenkins using the project-provided packages, started the server, opened the firewall, and created an administrative user. At this point, you can start exploring Jenkins.
When you’ve completed your exploration, follow the guide How to Configure Jenkins with SSL Using an Nginx Reverse Proxy on Ubuntu 20.04 to protect your passwords, as well as any sensitive system or product information that will be sent between your machine and the server in plain text to continue using Jenkins.
To learn more about what you can do using Jenkins, check out other tutorials on the subject: