Professional Documents
Culture Documents
Open in app
Search
Introduction
The original vision of cloud computing was automated, on-demand services that
scaled dynamically to meet demand.
While this vision is now a reality, it doesn’t happen on its own. Cloud automation is
complex and requires specialized tools, expertise, and hard work.
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 1/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
The plan is to build a container and push it to a container registry, all from within
Bitbucket Pipelines.
An integrated CI/CD service built into Bitbucket. It allows you to automatically build, test,
and even deploy your code based on a configuration file in your repository.
Essentially, we create containers in the cloud for you. Inside these containers, you can run
commands (like you might on a local machine) but with all the advantages of a fresh
system, customized and configured for your needs.
It’s a service that Bitbucket offers that allows for code building, testing, and
deployment all based on a configuration file from within the repository.
This file is called a YAML file called bitbucket-pipelines.yml that is located inside the
root of the repository.
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 2/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
This is so that specified users or Amazon EC2 instances can access your container
repositories and images.
You can use your preferred CLI to push, pull, and manage Docker images, Open
Container Initiative (OCI) images, and OCI compatible artifacts.
Registry
An Amazon ECR registry is provided to each AWS account; you can create image
repositories in your registry and store images in them.
Authorization token
Your client must authenticate to Amazon ECR registries as an AWS user before it can
push and pull images.
Repository
An Amazon ECR image repository contains your Docker images, Open Container
Initiative (OCI) images, and OCI compatible artifacts.
Repository policy
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 3/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
You can control access to your repositories and the images within them with
repository policies.
Image
You can push and pull container images to your repositories. You can use these
images locally on your development system, or you can use them in Amazon ECS
task definitions and Amazon EKS pod specifications.
For more information, see Using Amazon ECR images with Amazon ECS and Using
Amazon ECR Images with Amazon EKS.
What is Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by
using containers.
By doing so, thanks to the container, the developer can rest assured that the
application will run on any other Linux machine regardless of any customized
settings that machine might have that could differ from the machine used for
writing and testing the code.
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 4/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Since containers are only layers upon layers of changes, each new command you
create in a Docker image will create a new layer in the container.
When you run docker build . on the same directory as the Dockerfile, Docker
daemon will start building the image and packaging it so you can use it. Then you
can run docker run <image-name> to start a new container.
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 5/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
On this tutorial, we’ll be pushing a docker image to the AWS Elastic Container
Registry (ECR).
Building the application and configuring our AWS credentials is done by simply
calling for a docker build command and creating a pipe to push our image to ECR.
To use the pipe you should have a IAM user configured with programmatic access
or Web Identity Provider (OIDC) role, with the necessary permissions to push
docker images to your ECR repository.
You also need to set up a ECR container registry if you don’t already have on.
Here is a AWS ECR Getting started guide from AWS on how to set up a new registry.
image: atlassian/default-image:2
pipelines:
branches:
master:
- step:
name: Build and AWS Setup
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 6/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
services:
- docker
script:
# change directory to application folder
- cd application-folder
# creates variables (timestamp, image name and tag)
- export TIMESTAMP="$(date +%Y%m%d)"
- export IMAGE_NAME=application
- export TAG="$TIMESTAMP"
# builds docker image from a local dockerfile
- docker build -t application .
# tags image as a way to id it by the timestamp
- docker tag application application:$TIMESTAMP
# use pipe to push the image to AWS ECR
- pipe: atlassian/aws-ecr-push-image:1.3.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: us-east-2
IMAGE_NAME: application:$TIMESTAMP
TAGS: "$TIMESTAMP $BITBUCKET_BUILD_NUMBER"
Once our pipeline’s been commited, a code insight is generated along with
annotations, metrics, and reports by Bitbucket.
If the operation was successful, an image of the application should be located inside
an Elastic Container Registry repository.
Hope you found this article useful. Thank you for reading.
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 7/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Follow
Gabriel Pulga
--
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 8/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
-- 1
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 9/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Cloud Architect vs. Cloud Engineer: Choosing the Right Career Path
Making an important career decision in cloud computing
-- 7
Gabriel Pulga
--
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 10/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
-- 5
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 11/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Matteo Bianchi
-- 27
Lists
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 12/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Eric Anicet
--
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 13/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
-- 1
Shazab Tanveer
--
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 14/15
17/10/2023, 12:12 Building and Publishing a Docker Image to Amazon ECR using Bitbucket Pipelines | by Gabriel Pulga | AWS in Plain English
Ritesh Thakur
--
https://aws.plainenglish.io/building-and-publishing-a-docker-image-to-amazon-ecr-using-bitbucket-pipelines-718e2f8bb3dd 15/15