Unleashing Docker with
Pipelines in Bitbucket Cloud
PHILIP HODDER | DEVELOPER | ATLASSIAN | @_PHODDER_
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
Continuous Integration
master
master
feature/xyz
master
feature/xyz
master
feature/xyz
master
feature/xyz
master
production
feature/xyz
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
default:
- step:
script:
- ./run-tests
Branch
workflows
bitbucket-pipelines.yml
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
default:
- step:
script:
- ./run-tests
Branch
workflows
bitbucket-pipelines.yml
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
default:
- step:
script:
- ./run-tests
Branch
workflows
bitbucket-pipelines.yml
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
default:
- step:
script:
- ./run-tests
Branch
workflows
bitbucket-pipelines.yml
LOCAL/CI
STAGINGLOCAL/CI
STAGINGLOCAL/CI
STAGINGLOCAL/CI
STAGING PRODUCTIONLOCAL/CI
STAGING PRODUCTIONLOCAL/CI
STAGING PRODUCTIONLOCAL/CI
Configuration as Code
Configuration as Code
v.1 v.2
production
Adam’s changes
PRODUCTION
Configuration as Code
v.1 v.2
production
Adam’s changes
PRODUCTION
v.1
image: maven:3.3.3
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
...
Environment
configuration
bitbucket-pipelines.yml
image: maven:3.3.3
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
...
Environment
configuration
bitbucket-pipelines.yml
image: maven:3.3.9
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
...
Environment
configuration
bitbucket-pipelines.yml
CONTINUOUS INTEGRATION
Begin the journey
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
“Containers are changing the
data center the same way
containers changed global
trade.”
Jim Zemlin, Linux Foundation
Photo credit: Tristan Tussah - Horizon
Containers
Application level virtualisation, Utilises
already running OS and hardware.
Virtual Machines
OS level virtualisation. Need to start up
hypervisor and new OS.
Containers
Application level virtualisation. Utilises
already running OS and hardware.
Virtual Machines
OS level virtualisation. Need to spin up
hardware emulation and new OS.
Versioning
Retrieve the specific
container you need.
Additional Benefits
Extensibility
Build upon the existing
ecosystem.
Portable
Run the same image on
different infrastructure.
Versioning
Retrieve the specific
container you need.
Additional Benefits
Extensibility
Build upon the existing
ecosystem.
Portable
Run the same image on
different infrastructure.
Versioning
Retrieve the specific
container you need.
Additional Benefits
Extensibility
Build upon the existing
ecosystem.
Portable
Run the same image on
different infrastructure.
Source Code
Source Code Compiled Code
Source Code Compiled Code Running Code
Source Code Compiled Code Running Code
Dockerfile
Source Code Compiled Code Running Code
Dockerfile Docker image
Source Code Compiled Code Running Code
Dockerfile Docker image Docker container
FROM openjdk:8
WORKDIR /opt/lib
COPY my-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Example
Dockerfile
Docker image
Docker container
FROM openjdk:8
WORKDIR /opt/lib
COPY my-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Example
Dockerfile
Docker image
Docker container
FROM openjdk:8
WORKDIR /opt/lib
COPY my-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Example
Dockerfile
Docker image
Docker container
FROM openjdk:8
WORKDIR /opt/lib
COPY my-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Example
Dockerfile
Docker image
Docker container
FROM openjdk:8
WORKDIR /opt/lib
COPY my-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Example
Dockerfile
Docker image
Docker container
$ docker build -t phil/my-service:1.0 .
Step 1 : FROM openjdk:8
---> 17922730618d
Step 2 : WORKDIR /opt/lib
---> f2bb448254ae
...
Successfully built 6b362a9f73eb
Example
Dockerfile
Docker image
Docker container
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
phil/my-service 1.0 6b362a9f73eb 18 seconds ago 643.2 MB
Example
Dockerfile
Docker image
Docker container
$ docker run phil/my-service:1.0
Hello world!
Listening on port 80…
Example
Dockerfile
Docker image
Docker container
$ docker run -p 8080:80 phil/my-service:1.0
Hello world!
Listening on port 80…
Example
Dockerfile
Docker image
Docker container
$ docker run -p 8080:80 phil/my-service:1.0
Hello world!
Listening on port 80…
$ curl localhost:8080/healthcheck
{
"status": "ready"
}
Example
Dockerfile
Docker image
Docker container
Registries
A Docker Registry is an application
that stores and shares Docker images.
Docker Hub
Why Docker?
Overview
Microservices
Cloud
Simple
Build Configuration
Bitbucket Pipelines runs all pipelines inside of Docker
containers.
Docker in Production
Bitbucket Pipelines utilises Docker for running all of
our production services.
Containerisation isn’t new
Docker has solved issues enabling containers to enter
the mainstream.
Overview
Microservices
Cloud
Simple
Build Configuration
Bitbucket Pipelines runs all pipelines inside of Docker
containers.
Docker in Production
Bitbucket Pipelines utilises Docker for running all of
our production services.
Containerisation isn’t new
Docker has solved issues enabling containers to enter
the mainstream.
Why Docker?
Overview
Microservices
Cloud
Simple
Build Configuration
Bitbucket Pipelines runs all pipelines inside of Docker
containers.
Docker in Production
Bitbucket Pipelines utilises Docker for running all of
our production services.
Containerisation isn’t new
Docker has solved issues enabling containers to enter
the mainstream.
Why Docker?
Overview
Microservices
Cloud
Simple
Bitbucket Cloud Bitbucket Pipelines Pipelines Build Env
Why Docker?
Overview
Microservices
Cloud
Simple
Bitbucket Cloud Bitbucket Pipelines Pipelines Build Env
Why Docker?
Overview
Microservices
Cloud
Simple
Bitbucket Cloud Bitbucket Pipelines Pipelines Build Env
Why Docker?
Overview
Microservices
Cloud
Simple
Microservices solve many problems
Solves issues with fault tolerance, scaling, and
organising people.
Microservices create many problems
Increased development complexity, added release
complexity and new operational requirements.
Docker solves these new problems
Virtualisation reduces release complexity, Docker
Compose for development, and operation tooling
around containers.
Why Docker?
Overview
Microservices
Cloud
Simple
Microservices solve many problems
Solves issues with fault tolerance, scaling, and
organising people.
Microservices create many problems
Increased development complexity, added release
complexity and new operational requirements.
Docker solves these new problems
Virtualisation reduces release complexity, Docker
Compose for development, and operation tooling
around containers.
Why Docker?
Overview
Microservices
Cloud
Simple
Microservices solve many problems
Solves issues with fault tolerance, scaling, and
organising people.
Microservices create many problems
Increased development complexity, added release
complexity and new operational requirements.
Docker solves these new problems
Virtualisation reduces release complexity, Docker
Compose for development, and operation tooling
around containers.
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Overview
Microservices
Cloud
Simple
Virtualisation
The move to SaaS and IaaS requires virtualisation.
Scaling
Simple scaling out using a cloud provider ensures high
availability.
Cost
Running several virtual machines is expensive. Running
several containers is cheaper.
Why Docker?
Overview
Microservices
Cloud
Simple
Virtualisation
The move to SaaS and IaaS requires virtualisation.
Scaling
Simple scaling out using a cloud provider ensures high
availability.
Cost
Running several virtual machines is expensive. Running
several containers is cheaper.
Why Docker?
Overview
Microservices
Cloud
Simple
Virtualisation
The move to SaaS and IaaS requires virtualisation.
Scaling
Simple scaling out using a cloud provider ensures high
availability.
Cost
Running several virtual machines is expensive. Running
several containers is cheaper.
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
…
Overview
Microservices
Cloud
Simple
No Configuration Files
Previous tools required configuration files and Linux
knowledge.
Secure
Simply secure by default. Follow best practices and
you will stay secure.
Simply Powerful
Spend less time getting things working, and focus on
extending what you.
Why Docker?
Overview
Microservices
Cloud
Simple
No Configuration Files
Previous tools required configuration files and Linux
knowledge.
Secure
Simply secure by default. Follow best practices and
you will stay secure.
Simply Powerful
Spend less time getting things working, and focus on
extending what you.
Why Docker?
Overview
Microservices
Cloud
Simple
No Configuration Files
Previous tools required configuration files and Linux
knowledge.
Secure
Simply secure by default. Follow best practices and
you will stay secure.
Simply Powerful
Spend less time getting things working, and focus on
extending what you.
Why Docker?
Overview
Microservices
Cloud
Simple
Why Docker?
Let Docker
bring you to
the next
level.
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
More Services
Creating new services adds
complexity to testing.
Challenges
Growing Team
Onboarding new team
members is complicated.
Bug or Config?
Need to determine if
something is a bug or local
config issue.
More Services
Creating new services adds
complexity to testing.
Challenges
Growing Team
Onboarding new team
members is complicated.
Bug or Config?
Need to determine if
something is a bug or local
config issue.
More Services
Creating new services adds
complexity to testing.
Challenges
Growing Team
Onboarding new team
members is complicated.
Bug or Config?
Need to determine if
something is a bug or local
config issue.
FROM maven:3.3.9
RUN apt-get update -y && 
apt-get install -y python
Example
Dockerfile
Build and Push
.yml config
Example
Dockerfile
Build and Push
.yml config
$ docker build -t julia-adam/mvnpython:3.3.9
Step 1 : FROM maven:3.3.9
---> 17922730618d
...
Successfully built 6b362a9f73eb
$ docker login
. . .
$ docker push julia-adam/mvnpython:3.3.9
. . .
Example
Dockerfile
Build and Push
.yml config
$ docker build -t julia-adam/mvnpython:3.3.9
Step 1 : FROM maven:3.3.9
---> 17922730618d
...
Successfully built 6b362a9f73eb
$ docker login
. . .
$ docker push julia-adam/mvnpython:3.3.9
. . .
Example
Dockerfile
Build and Push
.yml config
$ docker build -t julia-adam/mvnpython:3.3.9
Step 1 : FROM maven:3.3.9
---> 17922730618d
...
Successfully built 6b362a9f73eb
$ docker login
. . .
$ docker push julia-adam/mvnpython:3.3.9
. . .
Example
Dockerfile
Build and Push
.yml config
image: julia-adam/mvnpython:3.3.9
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
...
Example
Dockerfile
Build and Push
.yml config
image:
name: myregistry.io/julia-adam/mvnpython:3.3.9
username: $USERNAME
password: $PASSWORD
pipelines:
branches:
master:
- step:
script:
- ./deploy-to-staging
production:
- step:
script:
- ./deploy-to-production
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Local Debug
CLI
$ docker run -it --volume=$(pwd):/debugDir 

--workdir=“/debugDir” --memory=4g 

--entrypoint=/bin/bash 

julia-adam/mvnpython:3.3.9
/# pwd
/debugDir
/# ls
src test scripts README.md
Photo credit: isjamesalive
$ docker run postgres:9.5.2
...
PostgreSQL init process complete; ready for
start up.
...
LOG: database system is ready to accept
connections
Dockerised
Database
Run Postgres
Extend Image
Define Services
$ cat create-table.sh
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username
"$POSTGRES_USER" <<
-EOSQL
CREATE DATABASE usermanagement;
CREATE TABLE accounts (uuid varchar(100)
primary key, email varchar(100) NOT NULL);
EOSQL
Dockerised
Database
Run Postgres
Extend Image
Define Services
st
Dockerised
Database
Run Postgres
Extend Image
Define Services
FROM postgres:9.5.2
COPY ./create-table.sh /docker-entrypoint-
initdb.d/create-table.sh
Dockerised
Database
Run Postgres
Extend Image
Define Services
$ docker build -t julia-and-adam/postgres .
Step 1 : FROM postgres:9.5.2
---> 17922730618d
Step 2 : ADD ./create-table.sh /docker-
entrypoint-initdb.d/create-table.sh
…
---> f2bb448254ae
Successfully built f2bb448254ae
Dockerised
Database
Run Postgres
Extend Image
Define Services
$ docker run julia-and-adam/postgres
...
/docker-entrypoint.sh: running /docker-
entrypoint-initdb.d/create-table.sh
CREATE DATABASE
CREATE TABLE
...
LOG: database system is ready to accept
connections
image: maven:3.3.3
pipelines:
default:
- step:
script:
- mvn package
services:
- postgres
definitions:
services:
postgres:
image: julia-and-adam/postgres:latest
Dockerised
Database
Run Postgres
Extend Image
Define Services
image: maven:3.3.3
pipelines:
default:
- step:
script:
- mvn package
services:
- postgres
definitions:
services:
postgres:
image: julia-and-adam/postgres:latest
Dockerised
Database
Run Postgres
Extend Image
Define Services
Dockerised
Application
Dockerfile
Pipelines Config
FROM openjdk:8
WORKDIR /opt/lib
COPY user-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Beyond
Dockerised
Application
Dockerfile
Pipelines Config
FROM openjdk:8
WORKDIR /opt/lib
COPY user-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Beyond
Dockerised
Application
Dockerfile
Pipelines Config
FROM openjdk:8
WORKDIR /opt/lib
COPY user-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Beyond
Dockerised
Application
Dockerfile
Pipelines Config
FROM openjdk:8
WORKDIR /opt/lib
COPY user-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Beyond
Dockerised
Application
Dockerfile
Pipelines Config
FROM openjdk:8
WORKDIR /opt/lib
COPY user-service*.jar /opt/lib/service.jar
CMD [“java”, "-jar", "/opt/lib/service.jar",
“prod.yml"]
Beyond
image: maven:3.3.3
pipelines:
default:
- step:
script:
- mvn package
- docker build -t user-service:latest .
options:
docker: true
Dockerised
Application
Dockerfile
Pipelines Config
Beyond
image: maven:3.3.3
pipelines:
default:
- step:
script:
- mvn package
- docker build -t user-service:latest .
services:
- postgres
definitions:
services:
postgres:
image: julia-and-adam/postgres:latest
options:
docker: true
Dockerised
Application
Dockerfile
Pipelines Config
Beyond
image: maven:3.3.3
pipelines:
default:
- step:
script:
- mvn package
- docker build -t user-service:latest .
- docker login -u $USERNAME -p $PASSWORD
- docker push user-service:latest
services:
- postgres
definitions:
services:
postgres:
image: julia-and-adam/postgres:latest
options:
docker: true
Dockerised
Application
Dockerfile
Pipelines Config
Beyond
Dockerised
Application
Dockerfile
Pipelines Config
Beyond
image: maven:3.3.3
pipelines:
branches:
production:
- step:
script:
- mvn package
- bash docker-build-and—push-to-prod
services:
- postgres
default:
- step:
...
definitions:
services:
postgres:
image: julia-and-adam/postgres:latest
options:
docker: true
Piece by Piece
Incremental gains add up quickly to
improve all aspects of your team’s
development cycle.
Agenda
CI with Bitbucket Pipelines
Overview of Docker
Integrating Docker with Pipelines
Recap
After
Docker containers for all services.
Running Pipelines. Promoting releases.
Before
Local dev was tough. No CI. Production
was breaking more often.
After
Docker containers for all services.
Running Pipelines. Promoting releases.
Before
Local dev was tough. No CI. Production
was breaking more often.
Docker Consistency
Containers enable stable and
consistent code through all
environments.
Recap
Pipelines ❤ Docker
With our Docker support, it’s
quick to get started using
Pipelines on Bitbucket Cloud.
Docker Simplifies
Cloud development is far
easier with containers.
Docker Consistency
Containers enable stable and
consistent code through all
environments.
Recap
Pipelines ❤ Docker
With our Docker support, it’s
quick to get started using
Pipelines on Bitbucket Cloud.
Docker Simplifies
Cloud development is far
easier with containers.
Docker Consistency
Containers enable stable and
consistent code through all
environments.
Recap
Pipelines ❤ Docker
With our Docker support, it’s
quick to get started using
Pipelines on Bitbucket Cloud.
Docker Simplifies
Cloud development is far
easier with containers.
Thank you!
PHILIP HODDER | DEVELOPER | ATLASSIAN | @_PHODDER_

Unleashing Docker with Pipelines in Bitbucket Cloud