We will learn how to automate Docker builds using Jenkins pipeline. We will
use PHP based application. I have already created a repo with source
code
+ Dockerfile. We will see how to create Docker image and upload into
Nexus Docker registry successfully.
Pre-requisites:
1. Jenkins is up and running
2. Docker installed on Jenkins instance. Click here to for integrating Docker and Jenkins
3. Docker and Docker pipelines plug-in are installed
4. Nexus is up and running and docker registry is configured. Click here to know how to do that.
5. port 80 is opened up in firewall rules to access phpApp running inside Docker container
Create an entry in Manage Credentials for connecting to Nexus
Go to Jenkins --> Manage Jenkins--> Click on Manage Credentials.
Enter Nexus user name and password with ID as nexus
Click on Save.
Step # 1 - Create a pipeline in Jenkins, name can be anything
Step # 2 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your account_d should be updated and repo should be updated.
We will learn how to automate Docker builds using Jenkins. We will use
Python based application. I have already created a repo with source code
+ Dockerfile. We will see how to create Docker image and upload into AWS ECR successfully. We will not be using AWS access keys to upload image into ECR, we will be using IAM role and attach to Jenkins instance to access ECR.
1. Jenkins is up and running
2. Docker installed on Jenkins instance. Click here to for integrating Docker and Jenkins
3. Docker and Docker pipelines plug-in are installed
4. Repo created in ECR, Click here to know how to do that.
5. Make sure port 8096 is opened up in firewall rules.
6. Create an IAM role with AmazonEC2ContainerRegistryFullAccess policy, attach role to Jenkins EC2 instance
7. Make sure AWS cli is installed in Jenkins instance.
Step # 1 - Create a pipeline in Jenkins, name can be anything
Step # 2 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your account_d should be updated and repo should be updated.
pipeline { agent any environment { registry = "acct_id.dkr.ecr.us-east-1.amazonaws.com/your_ecr_repo" }
We will learn how to automate Docker builds using Jenkins. We will use
Python based application. I have already created a repo with source code
+ Dockerfile. We will see how to create Docker image and upload into AWS ECR successfully.
Pre-requisites:
1. Jenkins is up and running
2. Docker installed on Jenkins instance
3. Docker and Docker pipelines plug-in are installed and Amazon ECR plug-in installed
4. Repo created in ECR, Click here to know how to do that.
5. port 8096 is opened up in firewall rules.
6. Access keys + secret keys from AWS account
Step # 1 - Add ECR Plug-in
Go to Jenkins, Manage Jenkins, Add Amazon ECR plug-in
Step #2 - Create Credentials for AWS ECR
Go to your Jenkins where you have installed Docker as well.
Go to credentials -->
Click on Global credentials
Click on Add Credentials
Choose AWS credentials
Add your AWS access keys and secret keys and save it
Note down the ID after saving.
Step # 3 - Create a scripted pipeline in Jenkins, name can be anything
Step # 4 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your account_d should be updated and repo should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
pipeline { agent any environment { registry = "account_id.dkr.ecr.us-east-2.amazonaws.com/myphpapp" //- update your credentials ID after creating credentials for connecting to Docker Hub registryCredential = 'Copy_ID_from_step_no_1_above' dockerImage = '' }
How to upload Docker images into Nexus docker Registry - Upload Docker images to Nexus Decker Registry.
Pre-requisites:
Docker is installed and up and running.
Nexus is up and running and Docker registry is already configured. If you have not configured yet, click here to setup Nexus 3 to configure as Docker Registry.
Steps to configure in Docker to upload Docker images to Nexus
login to EC2 instance where you have installed Docker, try to perform below commands:
Configure Docker service to use insecure registry with http. Create Docker daemon file if it does not exist.
sudo vi /etc/docker/daemon.json
Add entries like below:
Enter Nexus URL along with port number used for Docker registry.
Restart Docker daemon after above configuration changes.
sudo systemctl restart docker
sudo systemctl status docker
Make sure Docker was able to restart successfully. Press q to come out of above window.
Login to Docker Registry hosted in Nexus 3 Make sure you are able to login to Docker Registry hosted in Nexus by executing below command: sudo docker login -u admin nexus_public_dns_name:8085
Now enter the Nexus admin password(it will not show the password when you type which is ok)
Download Dockerized code
git clone https://bitbucket.org/ananthkannan/mydockerrepo; cd mydockerrepo/pythonApp Create a Docker image and tag the image per Nexus Registry
sudo docker build . -t nexus_public_dns_name:8085/mypythonapp
Push the image into Docker Registry sudo docker push nexus_public_dns_name:8085/mypythonapp
Verify if Docker image is uploaded into Nexus successfully
Login to Nexus, click on Browse, choose Docker registry