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.
- Automating builds
- Automating Docker image builds
- Automating Docker image upload into AWS ECR
- Automating Docker container provisioning
- Automating Docker image builds
- Automating Docker image upload into AWS ECR
- Automating Docker container provisioning
Watch here for YouTube channel:
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. 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
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"
}
stages {
stage('Cloning Git') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://github.com/akannan1087/myPythonDockerRepo']]])
}
}
// Building Docker images
stage('Building image') {
steps{
script {
dockerImage = docker.build registry
}
}
}
// Uploading Docker images into AWS ECR
Code for this video is here:
Make sure you fork my repo https://github.com/akannan1087/myPythonDockerRepo
and make changes in the pipeline accordingly.
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"
}
stages {
stage('Cloning Git') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://github.com/akannan1087/myPythonDockerRepo']]])
}
}
// Building Docker images
stage('Building image') {
steps{
script {
dockerImage = docker.build registry
}
}
}
// Uploading Docker images into AWS ECR
stage('Pushing to ECR') {
steps{
script {
sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin acct_id.dkr.ecr.us-east-1.amazonaws.com'
sh 'docker push acct_id.dkr.ecr.us-east-1.amazonaws.com/your_ecr_repo:latest'
}
}
}
// Stopping Docker containers for cleaner Docker run
stage('stop previous containers') {
steps {
sh 'docker ps -f name=mypythonContainer -q | xargs --no-run-if-empty docker container stop'
sh 'docker container ls -a -fname=mypythonContainer -q | xargs -r docker container rm'
}
}
stage('Docker Run') {
steps{
script {
sh 'docker run -d -p 8096:5000 --rm --name mypythonContainer acct_id.dkr.ecr.us-east-1.amazonaws.com/your_ecr_repo:latest'
}
}
}
}
}
steps{
script {
sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin acct_id.dkr.ecr.us-east-1.amazonaws.com'
sh 'docker push acct_id.dkr.ecr.us-east-1.amazonaws.com/your_ecr_repo:latest'
}
}
}
// Stopping Docker containers for cleaner Docker run
stage('stop previous containers') {
steps {
sh 'docker ps -f name=mypythonContainer -q | xargs --no-run-if-empty docker container stop'
sh 'docker container ls -a -fname=mypythonContainer -q | xargs -r docker container rm'
}
}
stage('Docker Run') {
steps{
script {
sh 'docker run -d -p 8096:5000 --rm --name mypythonContainer acct_id.dkr.ecr.us-east-1.amazonaws.com/your_ecr_repo:latest'
}
}
}
}
}
Step # 3 - Click on Build - Build the pipeline
Once you create the pipeline and changes values per your ECR account ID, click on Build now.
Steps # 4 - Check Docker images are uploaded into ECR
Login to ECR, click on your repo, now you should see the image got uploaded.
Steps # 5 - Access PythonApp in the browser which is running inside docker container
Once build is successful, go to browser and enter http://public_dns_name:8096
You should see page like below:





Great example for a newbie, is there a groovy version of the pipeline script, that you can share?
ReplyDeleteunable to push to ECR ang getting error : >>Unable to locate credentials. You can configure credentials by running "aws configure".
ReplyDeleteError: Cannot perform an interactive login from a non TTY device
When we create ECR in AWS , we have to select public, not private.
DeleteNice .
ReplyDeleteLooking for the best mobile app development company in Saudi Arabia?
ReplyDeleteWe specialize in building powerful, user-centric mobile apps tailored to your business goals. From concept to launch, our expert team delivers innovative solutions that drive results. Would you be ready to turn your idea into a high-performing app? Please book your FREE 30-minute consultation today and let’s bring your vision to life! Visit us now- https://www.apptunix.com/mobile-app-development-company-riyadh-saudi-arabia/?utm_source=Socialbookmarking&utm_medium=organic11aug25-azad
This is such a helpful blog! Companies in the region can benefit greatly from expert IT services in Dubai to drive innovation.
ReplyDeleteride sharing app development
IT company in Dubai
logistics app development company dubai
laundry app development
social media app development
mobile app development company in Saudi Arabia
This pipeline tutorial is very helpful, especially for beginners combining Jenkins with Docker. I liked the browser access step at the end—it makes the result more tangible. Looking forward to seeing if you plan to extend this to Kubernetes deployments in the future.
ReplyDelete53BFE7527A
ReplyDeleteinstagram türk gerçek takipçi
Footer Link Satın Al
Beğeni Satın Al
Pubg Mobile 10000 Uc Hilesi Bedava
Sons Of The Forest Hile Kodları
İnstagram Hikaye Bakma Hilesi
Cuphead APK Ölümsüzlük Hilesi
1000 Takipçi Hilesi Bedava TikTok
velvet swivel accent chair
Apptunix continues to set the benchmark for mobile app development in Dubai, helping startups and enterprises bring their digital visions to life! As a leading name in App Development Dubai
ReplyDelete, their innovative iOS, Android, and cross-platform solutions are driving the city’s digital transformation.