Continuous delivery with docker

93
Continuous delivery with Docker Run everything in Docker containers Johan Janssen, Info Support, @johanjanssen42

Transcript of Continuous delivery with docker

Page 1: Continuous delivery with docker

Continuous delivery with Docker

Run everything in Docker containersJohan Janssen, Info Support, @johanjanssen42

Page 2: Continuous delivery with docker
Page 3: Continuous delivery with docker

Content

Docker Application and CD pipeline in Docker Development in Docker Questions

Page 4: Continuous delivery with docker

Docker

Page 5: Continuous delivery with docker

Docker

Page 6: Continuous delivery with docker

Transportation issue

Page 7: Continuous delivery with docker

Transportation solution

Page 8: Continuous delivery with docker

Software issue

Page 9: Continuous delivery with docker

Software solution

Page 10: Continuous delivery with docker

Docker compatibility

Page 11: Continuous delivery with docker

Why Docker To enable continuous delivery Quickly provision environments Run the same software local and in

the cloud

Page 12: Continuous delivery with docker

Docker vs Virtual Machines

Page 13: Continuous delivery with docker

Docker vs Virtual Machines Disk space efficiency Memory efficiency Speed Compatibility (run anywhere) Isolation Versioning Internet of Things (Raspberry Pi

etc.)

Page 14: Continuous delivery with docker

My first Docker container

docker run -i -t ubuntu:yakkety /bin/bash

Page 15: Continuous delivery with docker

Docker usecases

DTAP environment

Build environment

Mainly running non-GUI applications

Continuous delivery, testing etc.

Development !

Page 16: Continuous delivery with docker

Application and CD pipeline in Docker

Page 17: Continuous delivery with docker

Deployment pipeline

Version control

CompileQuality checks

TestingDeployments

DevOps End users

EtceteraSetup environment

Page 18: Continuous delivery with docker

Automatic versus manual deployment

Continuous delivery

Continuous deployment

Page 19: Continuous delivery with docker

Deployment pipeline

Page 20: Continuous delivery with docker

Example build pipeline

TAP

D

1

2

3 4

678

9

5

Page 21: Continuous delivery with docker

What to deliver?

Page 22: Continuous delivery with docker

Dockerfiles directory structure Main directory

BuildAndRunScript.sh GeneralBase

Dockerfile SonarQube

Dockerfile

Page 23: Continuous delivery with docker

Dockerfile GeneralBaseFROM ubuntu:saucy

RUN apt-get -y install software-properties- commonRUN add-apt-repository ppa:webupd8team/javaRUN apt-get update && apt-get -y upgradeRUN echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | debconf-set-selectionsRUN apt-get -y install oracle-java7-installerENV JAVA_HOME /usr/lib/jvm/java-7-oracle

Page 24: Continuous delivery with docker

Build Create the Dockerfile Build the containers:

<optional>cd GeneralBasedocker.io build -t GeneralBase . cd .. </optional>

Page 25: Continuous delivery with docker
Page 26: Continuous delivery with docker

Dockerfile SonarFROM GeneralBase

RUN apt-get install -y wget unzipRUN wget http://dist.sonar.codehaus.org/sonarqube-4.2.zipRUN unzip sonarqube-4.2.zip -d /optRUN rm sonarqube-4.2.zip

EXPOSE 9000 EXPOSE 9092CMD ["/opt/sonarqube-4.2/bin/linux-x86-64/sonar.sh", "console", "/bin/bash"]

Page 27: Continuous delivery with docker

Build Create the Dockerfile Build the containers:

cd SonarQubedocker.io build -t SonarQube .

Page 28: Continuous delivery with docker

Run

Start the containerdocker.io run -p 9000:9000

–p 9092:9092 -d SonarQube

Page 29: Continuous delivery with docker

List all in(active) containers# docker.io ps –aCONTAINER ID: ecbecf77461b CREATED: 32 minutes ago STATUS: Up 32 minutes PORTS: 0.0.0.0:9000->9000/tcp, 0.0.0.0:9092->9092/tcp

Page 30: Continuous delivery with docker

Controlling containers

Start / stop / restartdocker [start/stop/restart] containerid

Follow SystemOut and SystemErrdocker logs -f containerid

Page 31: Continuous delivery with docker

We need lots of Docker containersGeneralBa

se

AppServerBase

Environment D

Environment T

Environment A

Environment P

Jenkins

JenkinsDataContainer

Sonar Gitblit Nexus

Page 32: Continuous delivery with docker
Page 33: Continuous delivery with docker

Data storage In the same container as the application In a data container / data volume On the host

Page 34: Continuous delivery with docker

Data volumes Dockerfile

ENV JENKINS_HOME /var/JenkinsData

Docker commandsdocker.io run -v /var/JenkinsData –name JenkinsDataContainer ubuntu:saucy true

docker.io run -p 8080:8080 --volumes-from JenkinsDataContainer -d Jenkins

Page 35: Continuous delivery with docker

Diskspace# docker.io images --tree└─ 179.9 MB Tags: ubuntu:saucy └─253.6 MB └─741.8 MB Tags: GeneralBase:latest └─763.6 MB Tags: AppServerBase:latest

… ├─763.6 MB Tags: EnvironmentP:latest └─865.6 MB Tags: Nexus:latest

└─808.3 MB Tags: Gitblit:latest └─901.5 MB Tags: Sonar:latest └─805.4 MB Tags: Jenkins:latest

Page 36: Continuous delivery with docker

Execution time

real 4m11.729suser 0m3.329s sys 0m10.054s

Page 37: Continuous delivery with docker

Docker overview

Page 38: Continuous delivery with docker

One ring to rule them all

Page 39: Continuous delivery with docker

Docker registry

Creating the Docker registrydocker run -p 5000:5000 registry

Page 40: Continuous delivery with docker

Updating containers

Page 41: Continuous delivery with docker

Docker client 1 (push) Modify container Commit

docker.io commit 064f192.168.56.31:5000/test-version-0.2

New containerid -> ff7e

Pushdocker.io push

192.168.56.31:5000/test-version-0.2

Page 42: Continuous delivery with docker

Docker client 2 (pull) Pull

docker.io pull 192.168.56.31:5000/

test-version-0.2

Rundocker.io run -i -t ff7e /bin/bash

Page 43: Continuous delivery with docker

Pull update onlydocker images -tree└─153b 194.2 MB test-version-0.1:latest

docker pull 192.168.56.31:5000/test-version-0.2 ff7e: Download complete153b: Download complete

docker images -tree└─153b 194.2 MB test-version-0.1:latest └─ff7e 194.2 MB test-version-0.2:latest

Page 44: Continuous delivery with docker

Orchestration tools Kubernetes Docker Swarm Mesos …

Page 45: Continuous delivery with docker

Orchestration tools Scalability Failover Rollouts and rollbacks Self healing Service discovery Load balancing …

Page 46: Continuous delivery with docker

Jenkins

Page 47: Continuous delivery with docker

Why Jenkins Simple to use Really popular

Used in many organizations Regular updates Big community creating plugins

etc.

Most developers already use it

Page 48: Continuous delivery with docker

Example build pipeline

TAP

D

1

2

3 4

678

9

5

Page 49: Continuous delivery with docker

Jenkins

Page 50: Continuous delivery with docker

Jenkinsfile pipeline { agent any tools { maven 'Maven 3.3.9' jdk 'jdk8' } stages {

stage ('Build') { steps { sh 'mvn clean install' }

Page 51: Continuous delivery with docker

Blue Ocean

Source: https://jenkins.io/blog/2016/12/19/declarative-pipeline-beta/

Page 52: Continuous delivery with docker

Keep it simple“Life is really simple, but we insist on making it complicated.”

- Confucius

Page 53: Continuous delivery with docker

Development environment

Page 54: Continuous delivery with docker
Page 55: Continuous delivery with docker
Page 56: Continuous delivery with docker
Page 57: Continuous delivery with docker
Page 58: Continuous delivery with docker
Page 59: Continuous delivery with docker

Dockerfile

FROM java:8-jdk

RUN wget …/netbeans-8.0.2-linux.shRUN chmod +x netbeans*.shRUN sh netbeans*.sh --silent

CMD /usr/local/netbeans-8.0.2/bin/netbeans

Page 60: Continuous delivery with docker

Persisting data on host

Docker run command: -v $PWD/workspace:/workspace

Page 61: Continuous delivery with docker

What to persist?

Workspace Plugins Application in application server Maven repo Configuration Entire home folder??

Page 62: Continuous delivery with docker

Different options

Page 63: Continuous delivery with docker

X11

Page 64: Continuous delivery with docker

No protocol specified error

No protocol specified error ->xhost local:root

Page 65: Continuous delivery with docker

General part DockerfileRUN wget …/netbeans-8.0.2-linux.shRUN chmod +x netbeans*.shRUN sh netbeans*.sh –silent// Set netbeans_default_userdir=/workspace/userdir RUN sed -i …// Set netbeans_default_cachedir=/workspace/cachedirRUN sed -i …

Page 66: Continuous delivery with docker

X11 Dockerfile

FROM java:8-jdk

// General part

CMD /usr/local/netbeans-8.0.2/bin/netbeans

Page 67: Continuous delivery with docker

X11 build and rundocker build -t netbeansx11 .

docker run -ti --rm \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $PWD/workspace:/workspace \ -v $PWD/m2:/root/.m2 \ -p 8081:8080 \ netbeansx11

Page 68: Continuous delivery with docker

VNC

Page 69: Continuous delivery with docker

VNC DockerfileFROM java:8-jdkENV DEBIAN_FRONTEND noninteractive RUN apt-get update RUN apt-get install -y xfce4 xvfb x11vnc supervisorRUN adduser --disabled-password --gecos '' johanADD vnc.conf /etc/supervisor/conf.d/// General partEXPOSE 5900CMD ["supervisord", "-n"]

Page 70: Continuous delivery with docker

VNC vnc.conf[program:xvfb]

[program:x11vnc]command=/usr/bin/x11vnc -forever -display :1process_name = x11vncautorestart=trueuser=johan

[program:xfce4]command=/usr/bin/xfce4-sessionprocess_name = xfce4autorestart=trueuser=johanenvironment=DISPLAY=":1",HOME="/home/johan"

Page 71: Continuous delivery with docker

VNC build and rundocker build -t netbeansvnc .

docker run -d \-v $PWD/workspace:/workspace \-v $PWD/m2:/root/.m2 \-p 5900:5900 \-p 8082:8080 \

netbeansvnc

Page 72: Continuous delivery with docker

XRDP

Page 73: Continuous delivery with docker

XRDP Dockerfile (1/2)FROM fedora:22RUN dnf -y groupinstall 'Xfce Desktop' && yum clean allCOPY Xclients /etc/skel/.XclientsRUN dnf -y install supervisor xrdp && dnf clean allRUN useradd johan && echo johan:secret | chpasswdCOPY xrdp.ini /etc/supervisord.d/

Page 74: Continuous delivery with docker

XRDP Dockerfile (2/2)# Allow all users to connectRUN sed -i '/TerminalServerUsers/d' /etc/xrdp/sesman.ini && sed -i '/TerminalServerAdmins/d' /etc/xrdp/sesman.iniRUN dnf -y install java java-develENV JAVA_HOME /usr/lib/jvm/java-openjdk// General partEXPOSE 3389CMD ["supervisord", "-n"]

Page 75: Continuous delivery with docker

XRDP xrdp.ini

[program:xrdp-sesman]command=/usr/sbin/xrdp-sesman --nodaemonprocess_name = xrdp-sesman

[program:xrdp]command=/usr/sbin/xrdp -nodaemonprocess_name = xrdp

Page 76: Continuous delivery with docker

XRDP build and rundocker build -t netbeansxrdp .

docker run -d \-v $PWD/workspace:/workspace \-v $PWD/m2:/root/.m2 \-p 3389:3389 \-p 8083:8080 \netbeansxrdp

Page 77: Continuous delivery with docker

Used by multiple teams

Team Frodo image

Base image

Team Bilbo image

Page 78: Continuous delivery with docker

Used by multiple teams

• App Gimli• App Elrond

Team Frodo

• App ElrondTeam Bilbo

• App RadagastTeam

Galadriel

App means

application server

etc.

Page 79: Continuous delivery with docker

Used by multiple teams

Where do we place

the Elrond App?

• App Gimli• App Elrond

Team Frodo

• App ElrondTeam Bilbo

• App RadagastTeam

Galadriel

Page 80: Continuous delivery with docker

Splitting the container

TomcatImage

Gimli Elrond Radagast

Page 81: Continuous delivery with docker

Splitting the container

FedoraImage

Development

environment

Page 82: Continuous delivery with docker

Docker Compose

Page 83: Continuous delivery with docker

Docker Compose

Define and run multi container Docker applications Using a Compose file Link containers ‘docker-compose up’ to start the

containers

Page 84: Continuous delivery with docker

Directory structure TomcatGimli

DockerFile TomcatElrond

DockerFile TomcatRadagast

Dockerfile DevEnv

Dockerfile docker-compose.yml

Page 85: Continuous delivery with docker

tomcatgimli: build: TomcatGimli

tomcatelrond: build: TomcatElrond

tomcatradagast: build: TomcatRadagast

developmentenvironment: build: DevEnv ports: - "3389:3389" links: - tomcatgimli:gimli # Makes gimli available on # http://gimli:8080 - tomcatelrond:elrond - tomcatradagast:radagast

Page 86: Continuous delivery with docker

Environment specific configuration

Use docker-compose.override.yml Put all the configuration in one container Create small containers with configuration

per environment that inherit the application container Commandline arguments

Page 87: Continuous delivery with docker

Eclipse Che“Eclipse Che is an IDE and developer workspace server that allows anyone to contribute to a project without having to install software.”

Page 88: Continuous delivery with docker

Conclusion Use a (private) Docker registry Keep environmental settings separate Use Jenkins to manage everything Do not add extra functionality like

OpenSSH Think about topics such as security,

monitoring and logging Inherit and/or compose containers Separate concerns in separate

containers

Page 89: Continuous delivery with docker

Isolation

Page 90: Continuous delivery with docker

Isolation

Page 91: Continuous delivery with docker

Isolation

Page 92: Continuous delivery with docker

Isolation

Page 93: Continuous delivery with docker

Questions

[email protected]@johanjanssen42

https://bitbucket.org/johanjanssen/dockeride