SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Using Docker for Development
© 2018 All Rights Reserved.
LAURA FRANK TACHO
Director of Engineering, CloudBees
© 2018 All Rights Reserved. !3landscape.cncf.io
© 2018 All Rights Reserved. !4
1 DOCKER COMPOSE BASICS
2 OPTIMIZING IMAGES
3 DEBUGGING IN CONTAINERS
© 2018 All Rights Reserved. !5
1 DOCKER COMPOSE BASICS
© 2018 All Rights Reserved.
Picking the Right Tools
TOO LOW LEVEL
TOO COMPLEX
OR ABSTRACTED
Building container images by hand
Running one-off containers
docker run commands that are wider
than a terminal window
Deploying every single code change
Setting up a multi-node cluster
Complicated READMEs or setup instructions
App declaration that is easy to read and edit
Access to logs
Ability to mount source code
Common tooling with minimal setup
Docker Compose
© 2018 All Rights Reserved. !7
Sample App: Cats vs Dogs
vote result
github.com/rheinwein/example-voting-app
© 2018 All Rights Reserved. !8
worker
.NET
vote
python
redis
redis
db
postgres
result
node-js
Sample App: Cats vs Dogs
© 2018 All Rights Reserved. !9
Use from DockerHub
Develop, build, and test
worker
.NET
vote
python
redis
redis
db
postgres
result
node-js
Sample App: Cats vs Dogs
© 2018 All Rights Reserved.
© 2018 All Rights Reserved. !11
What Happened?
example-voting-app $ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
db docker-entrypoint.sh postgres Up 5432/tcp
example-voting-app_result_1 nodemon --inspect=[::]:585 ... Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp
example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp
example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up
redis docker-entrypoint.sh redis ... Up 0.0.0.0:32774->6379/tcp
example-voting-app $ docker ps # filtering output
CONTAINER ID IMAGE COMMAND STATUS PORTS
7852e34c057f example-voting-app_worker "/bin/sh -c 'dotnet …" Up 6 minutes
3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp
b0d3c9cd007c example-voting-app_vote "python app.py” Up 6 minutes 0.0.0.0:5000->80/tcp
9702bb12b70b redis:alpine "docker-entrypoint.s…" Up 6 minutes 0.0.0.0:32774->6379/tcp
072da9ac67e3 example-voting-app_result "nodemon --inspect=[…" Up 6 minutes 0.0.0.0:5858->5858/tcp
© 2018 All Rights Reserved. !12
What Happened?
example-voting-app $ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
db docker-entrypoint.sh postgres Up 5432/tcp
example-voting-app_result_1 nodemon --inspect=[::]:585 ... Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp
example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp
example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up
redis docker-entrypoint.sh redis ... Up 0.0.0.0:32774->6379/tcp
example-voting-app $ docker ps # filtering output
CONTAINER ID IMAGE COMMAND STATUS PORTS
7852e34c057f example-voting-app_worker "/bin/sh -c 'dotnet …" Up 6 minutes
3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp
b0d3c9cd007c example-voting-app_vote "python app.py” Up 6 minutes 0.0.0.0:5000->80/tcp
9702bb12b70b redis:alpine "docker-entrypoint.s…" Up 6 minutes 0.0.0.0:32774->6379/tcp
072da9ac67e3 example-voting-app_result "nodemon --inspect=[…" Up 6 minutes 0.0.0.0:5858->5858/tcp
3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp
db docker-entrypoint.sh postgres Up 5432/tcp
© 2018 All Rights Reserved. !13
Text Editor
Container
Browser
😎
Source Code
© 2018 All Rights Reserved. !14
Accessing Source Code
version: "3"
services:
result:
build: ./result
command: nodemon server.js
volumes:
- ./result:/app
ports:
- "5001:80"
- "5858:5858"
networks:
- front-tier
- back-tier
Runtime vs Buildtime
This will overwrite the code copied into
the image at buildtime. Now you’re able to
see updates in the browser instantly.
docker-compose.yml
© 2018 All Rights Reserved.
© 2018 All Rights Reserved. !16
version: "3"
services:
redis:
image: redis:alpine
container_name: redis
ports:
- "6379"
networks:
- back-tier
def get_redis():
if not hasattr(g, 'redis'):
g.redis = Redis(host="redis", db=0, socket_timeout=5)
return g.redis
vote/app.pydocker-compose.yml
Managing External Dependencies
© 2018 All Rights Reserved. !17
You don’t need to run your database
in a container.
© 2018 All Rights Reserved. !18
‣ Containers are meant to be ephemeral. If you store application data in the
container, that data is lost when the container is stopped and removed
‣ Using volumes allows data to stick around outside of the lifecycle of the
container
‣ Many drivers are available for cloud services
‣ You can also use your local disk
Data Volumes
© 2018 All Rights Reserved. !19
‣ If you store application data in the
container, that data is lost when the
container is stopped and removed
‣ Using volumes allows data to persist
beyond the lifecycle of the container
‣ Many drivers are available for
cloud services
‣ You can also use your local disk
Data Volumes
services:
...
db:
image: postgres:9.4
container_name: db
volumes:
- "db-data:/var/lib/postgresql/data"
networks:
- back-tier
volumes:
db-data:
docker-compose.yml
© 2018 All Rights Reserved. !20
2 OPTIMIZING IMAGES
© 2018 All Rights Reserved. !21
Dockerfiles and container images are
the heart of your application.
Everything else in the container
ecosystem assumes that you have your
source code available as a container
time. Virtually every type of application
can run inside a container.
© 2018 All Rights Reserved. !22
FROM node:10.9-alpine
RUN mkdir -p /app
WORKDIR /app
RUN npm install -g nodemon
RUN npm config set registry https://
registry.npmjs.org
COPY package.json /app/package.json
RUN npm install 
&& npm ls 
&& npm cache clean --force 
&& mv /app/node_modules /node_modules
COPY . /app
ENV PORT 80
EXPOSE 80
CMD ["node", "server.js"]
A Dockerfile a list of instructions outlining
packages, files, dependencies, and
everything required for your application to
run.
result/Dockerfile
© 2018 All Rights Reserved. !23
FROM node:10.9-alpine
RUN mkdir -p /app
WORKDIR /app
RUN npm install -g nodemon
RUN npm config set registry https://
registry.npmjs.org
COPY package.json /app/package.json
RUN npm install 
&& npm ls 
&& npm cache clean --force 
&& mv /app/node_modules /node_modules
COPY . /app
ENV PORT 80
EXPOSE 80
CMD ["node", "server.js"]
Depending on your language, select a
suitable base image and then install the
packages and run setup commands
necessary for your application.
In general, aim to have as small of an
image as possible, but you can always
optimize later.
result/Dockerfile
© 2018 All Rights Reserved. !24
For faster dev cycles, optimize your images.
© 2018 All Rights Reserved. !25
If nothing changes in a layer command, Docker
will use an existing version.
At buildtime, these cache hits can drastically
reduce the time to build and push your image.
Cache misses will add extra time, and you can
optimize your image to avoid them during
development.
Use Caching Effectively
© 2018 All Rights Reserved. !26
Order Layers for Better Cache Usage
Copy over package or dependency manifests and install those before copying the
rest of the code. Lockfiles change infrequently, so it’s not necessary to reinstall
everything all the time.
COPY package.json /app/package.json
RUN npm install 
&& npm ls 
&& npm cache clean --force 
&& mv /app/node_modules /node_modules
COPY . /app
© 2018 All Rights Reserved.
© 2018 All Rights Reserved. !28
FROM node:10.9-alpine
RUN mkdir -p /app
WORKDIR /app
RUN npm install -g nodemon
RUN npm config set registry https://
registry.npmjs.org
COPY package.json /app/package.json
RUN npm install 
&& npm ls 
&& npm cache clean --force 
&& mv /app/node_modules /node_modules
COPY . /app
ENV PORT 80
EXPOSE 80
CMD ["node", "server.js"]
Each of these instructions results in a
layer in your image. More layers means
a bigger image, which means:
‣ Longer builds
‣ Longer to push
‣ Longer to pull
result/Dockerfile
© 2018 All Rights Reserved. !29
Chain RUN Commands
Reducing the number of layers will reduce the overall size of your image,
even if the output is the same.
COPY package.json /app/package.json
RUN npm install 
&& npm ls 
&& npm cache clean --force 
&& mv /app/node_modules /node_modules
COPY . /app
COPY package.json /app/package.json
RUN npm install
RUN npm ls
RUN npm cache clean --force
RUN mv /app/node_modules /node_modules
COPY . /app
92MB83.9MB
© 2018 All Rights Reserved. !30
Pick Base Images Wisely!
By now, almost every major language
or framework maintains a slim version
of their library image, tagged with slim
or specifically with alpine.
Warning: the size of an image on
Docker Hub is the compressed size.
hub.docker.com/_/node
© 2018 All Rights Reserved. !31
Avoid Anti-Patterns
‣ Simultaneous Innovation
‣ Skipping the fundamentals like giving love to your Dockerfiles
‣ Forgetting other development best practices like pinning dependencies to
versions — this stuff still matters even if you’re using containers
‣ For example, don’t use the latest tag
© 2018 All Rights Reserved. !32
Laura’s Model for Super Duper Container Success
Get it running in a container. Create an application template and get
that running. Then optimize your Dockerfile. Then worry about
everything else.
© 2018 All Rights Reserved. !33
3 DEBUGGING IN CONTAINERS
© 2018 All Rights Reserved. !34
You can access log output either via Docker Compose or Docker directly.
$ docker-compose logs # this returns all logs for all services
db | LOG: stats_timestamp 2018-09-12 10:35:03.286676+00 is later than collector's time
2018-09-12 10:35:03.262932+00 for database 12141
result_1 | [nodemon] restarting due to changes...
result_1 | [nodemon] starting `node --inspect=[::]:5858 server.js`
result_1 | Debugger listening on ws://[::]:5858/f6dd534f-1976-421c-b4e2-8d3b1baf2622
result_1 | For help, see: https://nodejs.org/en/docs/inspector
result_1 | App running on port 80
result_1 | Connected to db
result_1 | Debugger attached.
redis | 1:M 12 Sep 08:33:52.991 # WARNING: The TCP backlog setting of 511 cannot be enforced
because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis | 1:M 12 Sep 08:33:52.991 # Server initialized
Viewing Log Output
© 2018 All Rights Reserved. !35
Viewing Log Output
Logs are visible by default when starting your app with docker-compose up. If
you prefer a tidy terminal, use up with the detached flag. You can get logs per
service later. Tip: timestamps are available with a flag.
$ docker-compose up -d
...
$ docker-compose logs -t worker # docker logs -t example-voting-app_worker_1
worker_1 | 2018-09-12T08:22:49.367373200Z Waiting for db
worker_1 | 2018-09-12T08:22:50.371369500Z Waiting for db
worker_1 | 2018-09-12T08:22:53.526120800Z Connected to db
worker_1 | 2018-09-12T08:22:53.541336500Z Found redis at 172.20.0.2
worker_1 | 2018-09-12T08:22:53.541400100Z Connecting to redis
worker_1 | 2018-09-12T08:33:54.478754500Z Connected to db
worker_1 | 2018-09-12T08:33:54.495682400Z Found redis at 172.20.0.2
worker_1 | 2018-09-12T08:33:54.496062600Z Connecting to redis
worker_1 | 2018-09-12T08:34:15.528315300Z Processing vote for 'b' by '2d4e42c6c94f4e53'
worker_1 | 2018-09-12T08:37:11.883353600Z Processing vote for 'a' by ‘2d4e42c6c94f4e53'
© 2018 All Rights Reserved. !36
Tip: set many options on Docker Compose directly, not on subcommands.
--verbose Show more output
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Debugging Compose Itself
© 2018 All Rights Reserved. !37
Starting a Container in Interactive Mode
Want a shell to debug startup commands without the container
exiting on failure?
version: "3"
services:
web:
image: ubuntu:18.04
tty: true
stdin_open: true
entrypoint: "/bin/bash"
docker run -it ubuntu:18:04 /bin/bash
# volume mount if you need to with `-v
source:target`
with docker-compose run web with Docker only
© 2018 All Rights Reserved. !38
‣ docker top will give you a list of all running processes in a container
‣ docker inspect (name|id) will give you ALL of the details about a given resource
Helpful Docker Commands
‣ You can use the --format flag and pass in a Go template
‣ For example, to get the IP(s) of a running container:
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 
$CONTAINER_ID
© 2018 All Rights Reserved. !39
Running a Debugger
version: "3"
services:
result:
build: ./result
command: nodemon --inspect=0.0.0.0:5858 server.js
volumes:
- ./result:/app
ports:
- “5001:80"
- "5858:5858"
networks:
- front-tier
- back-tier
Maintain access to debugging tools by
publishing the ports.
You may also have to update the
command or entrypoint to access
debugging tools.
© 2018 All Rights Reserved. !40
Visit the CodeShip team
at our booth!

Mais conteúdo relacionado

Mais procurados

Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetescraigbox
 
Things I've learned working with Docker Support
Things I've learned working with Docker SupportThings I've learned working with Docker Support
Things I've learned working with Docker SupportSujay Pillai
 
Continuous Deployment with Jenkins on Kubernetes
Continuous Deployment with Jenkins on KubernetesContinuous Deployment with Jenkins on Kubernetes
Continuous Deployment with Jenkins on KubernetesMatt Baldwin
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWSManish Jain
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesSujay Pillai
 
Infrastructure as code
Infrastructure as codeInfrastructure as code
Infrastructure as codeAxel Quack
 
Container Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in productionContainer Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in productionMike Splain
 
docker-machine, docker-compose, docker-swarm 覚書
docker-machine, docker-compose, docker-swarm 覚書docker-machine, docker-compose, docker-swarm 覚書
docker-machine, docker-compose, docker-swarm 覚書じゅん なかざ
 
DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDocker, Inc.
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discoveryDocker, Inc.
 
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and BeyondTectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and BeyondCoreOS
 
An Introduction to the Kubernetes API
An Introduction to the Kubernetes APIAn Introduction to the Kubernetes API
An Introduction to the Kubernetes APIStefan Schimanski
 
Api versioning w_docker_and_nginx
Api versioning w_docker_and_nginxApi versioning w_docker_and_nginx
Api versioning w_docker_and_nginxLee Wilkins
 
Testing Distributed Micro Services. Agile Testing Days 2017
Testing Distributed Micro Services. Agile Testing Days 2017Testing Distributed Micro Services. Agile Testing Days 2017
Testing Distributed Micro Services. Agile Testing Days 2017Carlos Sanchez
 
Docker-hanoi meetup #1: introduction about Docker
Docker-hanoi meetup #1: introduction about DockerDocker-hanoi meetup #1: introduction about Docker
Docker-hanoi meetup #1: introduction about DockerNguyen Anh Tu
 
Api Versioning with Docker and Nginx
Api Versioning with Docker and NginxApi Versioning with Docker and Nginx
Api Versioning with Docker and Nginxtech.kartenmacherei
 
Divide and Conquer: Easier Continuous Delivery using Micro-Services
Divide and Conquer: Easier Continuous Delivery using Micro-ServicesDivide and Conquer: Easier Continuous Delivery using Micro-Services
Divide and Conquer: Easier Continuous Delivery using Micro-ServicesCarlos Sanchez
 
Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Hao H. Zhang
 

Mais procurados (20)

Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetes
 
Things I've learned working with Docker Support
Things I've learned working with Docker SupportThings I've learned working with Docker Support
Things I've learned working with Docker Support
 
Continuous Deployment with Jenkins on Kubernetes
Continuous Deployment with Jenkins on KubernetesContinuous Deployment with Jenkins on Kubernetes
Continuous Deployment with Jenkins on Kubernetes
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWS
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content Services
 
Infrastructure as code
Infrastructure as codeInfrastructure as code
Infrastructure as code
 
Container Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in productionContainer Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in production
 
docker-machine, docker-compose, docker-swarm 覚書
docker-machine, docker-compose, docker-swarm 覚書docker-machine, docker-compose, docker-swarm 覚書
docker-machine, docker-compose, docker-swarm 覚書
 
DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker Captains
 
Deep dive in container service discovery
Deep dive in container service discoveryDeep dive in container service discovery
Deep dive in container service discovery
 
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and BeyondTectonic Summit 2016: Kubernetes 1.5 and Beyond
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
 
An Introduction to the Kubernetes API
An Introduction to the Kubernetes APIAn Introduction to the Kubernetes API
An Introduction to the Kubernetes API
 
Api versioning w_docker_and_nginx
Api versioning w_docker_and_nginxApi versioning w_docker_and_nginx
Api versioning w_docker_and_nginx
 
Testing Distributed Micro Services. Agile Testing Days 2017
Testing Distributed Micro Services. Agile Testing Days 2017Testing Distributed Micro Services. Agile Testing Days 2017
Testing Distributed Micro Services. Agile Testing Days 2017
 
Docker-hanoi meetup #1: introduction about Docker
Docker-hanoi meetup #1: introduction about DockerDocker-hanoi meetup #1: introduction about Docker
Docker-hanoi meetup #1: introduction about Docker
 
Beyond static configuration
Beyond static configurationBeyond static configuration
Beyond static configuration
 
Api Versioning with Docker and Nginx
Api Versioning with Docker and NginxApi Versioning with Docker and Nginx
Api Versioning with Docker and Nginx
 
Divide and Conquer: Easier Continuous Delivery using Micro-Services
Divide and Conquer: Easier Continuous Delivery using Micro-ServicesDivide and Conquer: Easier Continuous Delivery using Micro-Services
Divide and Conquer: Easier Continuous Delivery using Micro-Services
 
Docker Support
Docker Support Docker Support
Docker Support
 
Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2
 

Semelhante a Using Docker For Development

DCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker ContainersDCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker ContainersDocker, Inc.
 
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPHands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPDana Luther
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned RightScale
 
Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Nicola Paolucci
 
Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3Velocidex Enterprises
 
EMC World 2016 - code.09 Introduction to the Docker Platform
EMC World 2016 - code.09 Introduction to the Docker PlatformEMC World 2016 - code.09 Introduction to the Docker Platform
EMC World 2016 - code.09 Introduction to the Docker Platform{code}
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataInfluxData
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tipsSamuel Chow
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020CloudHero
 
Securing Containers - Sathyajit Bhat - Adobe
Securing Containers - Sathyajit Bhat - AdobeSecuring Containers - Sathyajit Bhat - Adobe
Securing Containers - Sathyajit Bhat - AdobeCodeOps Technologies LLP
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionBen Hall
 
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...Aleksey Tkachenko
 
Be a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeBe a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeNicola Paolucci
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesRobert Lemke
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday developmentJustyna Ilczuk
 
Laravel, docker, kubernetes
Laravel, docker, kubernetesLaravel, docker, kubernetes
Laravel, docker, kubernetesPeter Mein
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik DornJDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik DornPROIDEA
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Patrick Chanezon
 

Semelhante a Using Docker For Development (20)

DCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker ContainersDCEU 18: Developing with Docker Containers
DCEU 18: Developing with Docker Containers
 
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPHands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
 
Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned  Real-World Docker: 10 Things We've Learned
Real-World Docker: 10 Things We've Learned
 
Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)
 
Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3
 
EMC World 2016 - code.09 Introduction to the Docker Platform
EMC World 2016 - code.09 Introduction to the Docker PlatformEMC World 2016 - code.09 Introduction to the Docker Platform
EMC World 2016 - code.09 Introduction to the Docker Platform
 
Introduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxDataIntroduction to Docker and Monitoring with InfluxData
Introduction to Docker and Monitoring with InfluxData
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020Docker Essentials Workshop— Innovation Labs July 2020
Docker Essentials Workshop— Innovation Labs July 2020
 
Before & After Docker Init
Before & After Docker InitBefore & After Docker Init
Before & After Docker Init
 
Securing Containers - Sathyajit Bhat - Adobe
Securing Containers - Sathyajit Bhat - AdobeSecuring Containers - Sathyajit Bhat - Adobe
Securing Containers - Sathyajit Bhat - Adobe
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and Production
 
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...Docman - The swiss army knife for Drupal multisite docroot management and dep...
Docman - The swiss army knife for Drupal multisite docroot management and dep...
 
Be a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeBe a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the trade
 
Scaleable PHP Applications in Kubernetes
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
Laravel, docker, kubernetes
Laravel, docker, kubernetesLaravel, docker, kubernetes
Laravel, docker, kubernetes
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik DornJDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
 
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
Docker Azure Friday OSS March 2017 - Developing and deploying Java & Linux on...
 

Mais de Laura Frank Tacho

Scalable and Available Services with Docker and Kubernetes
Scalable and Available Services with Docker and KubernetesScalable and Available Services with Docker and Kubernetes
Scalable and Available Services with Docker and KubernetesLaura Frank Tacho
 
SwarmKit in Theory and Practice
SwarmKit in Theory and PracticeSwarmKit in Theory and Practice
SwarmKit in Theory and PracticeLaura Frank Tacho
 
Everything You Thought You Already Knew About Orchestration
Everything You Thought You Already Knew About OrchestrationEverything You Thought You Already Knew About Orchestration
Everything You Thought You Already Knew About OrchestrationLaura Frank Tacho
 
Building Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with DockerBuilding Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with DockerLaura Frank Tacho
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with DockerLaura Frank Tacho
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareLaura Frank Tacho
 
Rails Applications with Docker
Rails Applications with DockerRails Applications with Docker
Rails Applications with DockerLaura Frank Tacho
 

Mais de Laura Frank Tacho (9)

The Container Shame Spiral
The Container Shame SpiralThe Container Shame Spiral
The Container Shame Spiral
 
Scalable and Available Services with Docker and Kubernetes
Scalable and Available Services with Docker and KubernetesScalable and Available Services with Docker and Kubernetes
Scalable and Available Services with Docker and Kubernetes
 
SwarmKit in Theory and Practice
SwarmKit in Theory and PracticeSwarmKit in Theory and Practice
SwarmKit in Theory and Practice
 
Everything You Thought You Already Knew About Orchestration
Everything You Thought You Already Knew About OrchestrationEverything You Thought You Already Knew About Orchestration
Everything You Thought You Already Knew About Orchestration
 
Building Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with DockerBuilding Efficient Parallel Testing Platforms with Docker
Building Efficient Parallel Testing Platforms with Docker
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with Docker
 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your Software
 
Happier Teams Through Tools
Happier Teams Through ToolsHappier Teams Through Tools
Happier Teams Through Tools
 
Rails Applications with Docker
Rails Applications with DockerRails Applications with Docker
Rails Applications with Docker
 

Último

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 

Último (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 

Using Docker For Development

  • 1. Using Docker for Development
  • 2. © 2018 All Rights Reserved. LAURA FRANK TACHO Director of Engineering, CloudBees
  • 3. © 2018 All Rights Reserved. !3landscape.cncf.io
  • 4. © 2018 All Rights Reserved. !4 1 DOCKER COMPOSE BASICS 2 OPTIMIZING IMAGES 3 DEBUGGING IN CONTAINERS
  • 5. © 2018 All Rights Reserved. !5 1 DOCKER COMPOSE BASICS
  • 6. © 2018 All Rights Reserved. Picking the Right Tools TOO LOW LEVEL TOO COMPLEX OR ABSTRACTED Building container images by hand Running one-off containers docker run commands that are wider than a terminal window Deploying every single code change Setting up a multi-node cluster Complicated READMEs or setup instructions App declaration that is easy to read and edit Access to logs Ability to mount source code Common tooling with minimal setup Docker Compose
  • 7. © 2018 All Rights Reserved. !7 Sample App: Cats vs Dogs vote result github.com/rheinwein/example-voting-app
  • 8. © 2018 All Rights Reserved. !8 worker .NET vote python redis redis db postgres result node-js Sample App: Cats vs Dogs
  • 9. © 2018 All Rights Reserved. !9 Use from DockerHub Develop, build, and test worker .NET vote python redis redis db postgres result node-js Sample App: Cats vs Dogs
  • 10. © 2018 All Rights Reserved.
  • 11. © 2018 All Rights Reserved. !11 What Happened? example-voting-app $ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon --inspect=[::]:585 ... Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32774->6379/tcp example-voting-app $ docker ps # filtering output CONTAINER ID IMAGE COMMAND STATUS PORTS 7852e34c057f example-voting-app_worker "/bin/sh -c 'dotnet …" Up 6 minutes 3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp b0d3c9cd007c example-voting-app_vote "python app.py” Up 6 minutes 0.0.0.0:5000->80/tcp 9702bb12b70b redis:alpine "docker-entrypoint.s…" Up 6 minutes 0.0.0.0:32774->6379/tcp 072da9ac67e3 example-voting-app_result "nodemon --inspect=[…" Up 6 minutes 0.0.0.0:5858->5858/tcp
  • 12. © 2018 All Rights Reserved. !12 What Happened? example-voting-app $ docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------- db docker-entrypoint.sh postgres Up 5432/tcp example-voting-app_result_1 nodemon --inspect=[::]:585 ... Up 0.0.0.0:5858->5858/tcp, 0.0.0.0:5001->80/tcp example-voting-app_vote_1 python app.py Up 0.0.0.0:5000->80/tcp example-voting-app_worker_1 /bin/sh -c dotnet src/Work ... Up redis docker-entrypoint.sh redis ... Up 0.0.0.0:32774->6379/tcp example-voting-app $ docker ps # filtering output CONTAINER ID IMAGE COMMAND STATUS PORTS 7852e34c057f example-voting-app_worker "/bin/sh -c 'dotnet …" Up 6 minutes 3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp b0d3c9cd007c example-voting-app_vote "python app.py” Up 6 minutes 0.0.0.0:5000->80/tcp 9702bb12b70b redis:alpine "docker-entrypoint.s…" Up 6 minutes 0.0.0.0:32774->6379/tcp 072da9ac67e3 example-voting-app_result "nodemon --inspect=[…" Up 6 minutes 0.0.0.0:5858->5858/tcp 3bca5cc2eb09 postgres:9.4 "docker-entrypoint.s…" Up 6 minutes 5432/tcp db docker-entrypoint.sh postgres Up 5432/tcp
  • 13. © 2018 All Rights Reserved. !13 Text Editor Container Browser 😎 Source Code
  • 14. © 2018 All Rights Reserved. !14 Accessing Source Code version: "3" services: result: build: ./result command: nodemon server.js volumes: - ./result:/app ports: - "5001:80" - "5858:5858" networks: - front-tier - back-tier Runtime vs Buildtime This will overwrite the code copied into the image at buildtime. Now you’re able to see updates in the browser instantly. docker-compose.yml
  • 15. © 2018 All Rights Reserved.
  • 16. © 2018 All Rights Reserved. !16 version: "3" services: redis: image: redis:alpine container_name: redis ports: - "6379" networks: - back-tier def get_redis(): if not hasattr(g, 'redis'): g.redis = Redis(host="redis", db=0, socket_timeout=5) return g.redis vote/app.pydocker-compose.yml Managing External Dependencies
  • 17. © 2018 All Rights Reserved. !17 You don’t need to run your database in a container.
  • 18. © 2018 All Rights Reserved. !18 ‣ Containers are meant to be ephemeral. If you store application data in the container, that data is lost when the container is stopped and removed ‣ Using volumes allows data to stick around outside of the lifecycle of the container ‣ Many drivers are available for cloud services ‣ You can also use your local disk Data Volumes
  • 19. © 2018 All Rights Reserved. !19 ‣ If you store application data in the container, that data is lost when the container is stopped and removed ‣ Using volumes allows data to persist beyond the lifecycle of the container ‣ Many drivers are available for cloud services ‣ You can also use your local disk Data Volumes services: ... db: image: postgres:9.4 container_name: db volumes: - "db-data:/var/lib/postgresql/data" networks: - back-tier volumes: db-data: docker-compose.yml
  • 20. © 2018 All Rights Reserved. !20 2 OPTIMIZING IMAGES
  • 21. © 2018 All Rights Reserved. !21 Dockerfiles and container images are the heart of your application. Everything else in the container ecosystem assumes that you have your source code available as a container time. Virtually every type of application can run inside a container.
  • 22. © 2018 All Rights Reserved. !22 FROM node:10.9-alpine RUN mkdir -p /app WORKDIR /app RUN npm install -g nodemon RUN npm config set registry https:// registry.npmjs.org COPY package.json /app/package.json RUN npm install && npm ls && npm cache clean --force && mv /app/node_modules /node_modules COPY . /app ENV PORT 80 EXPOSE 80 CMD ["node", "server.js"] A Dockerfile a list of instructions outlining packages, files, dependencies, and everything required for your application to run. result/Dockerfile
  • 23. © 2018 All Rights Reserved. !23 FROM node:10.9-alpine RUN mkdir -p /app WORKDIR /app RUN npm install -g nodemon RUN npm config set registry https:// registry.npmjs.org COPY package.json /app/package.json RUN npm install && npm ls && npm cache clean --force && mv /app/node_modules /node_modules COPY . /app ENV PORT 80 EXPOSE 80 CMD ["node", "server.js"] Depending on your language, select a suitable base image and then install the packages and run setup commands necessary for your application. In general, aim to have as small of an image as possible, but you can always optimize later. result/Dockerfile
  • 24. © 2018 All Rights Reserved. !24 For faster dev cycles, optimize your images.
  • 25. © 2018 All Rights Reserved. !25 If nothing changes in a layer command, Docker will use an existing version. At buildtime, these cache hits can drastically reduce the time to build and push your image. Cache misses will add extra time, and you can optimize your image to avoid them during development. Use Caching Effectively
  • 26. © 2018 All Rights Reserved. !26 Order Layers for Better Cache Usage Copy over package or dependency manifests and install those before copying the rest of the code. Lockfiles change infrequently, so it’s not necessary to reinstall everything all the time. COPY package.json /app/package.json RUN npm install && npm ls && npm cache clean --force && mv /app/node_modules /node_modules COPY . /app
  • 27. © 2018 All Rights Reserved.
  • 28. © 2018 All Rights Reserved. !28 FROM node:10.9-alpine RUN mkdir -p /app WORKDIR /app RUN npm install -g nodemon RUN npm config set registry https:// registry.npmjs.org COPY package.json /app/package.json RUN npm install && npm ls && npm cache clean --force && mv /app/node_modules /node_modules COPY . /app ENV PORT 80 EXPOSE 80 CMD ["node", "server.js"] Each of these instructions results in a layer in your image. More layers means a bigger image, which means: ‣ Longer builds ‣ Longer to push ‣ Longer to pull result/Dockerfile
  • 29. © 2018 All Rights Reserved. !29 Chain RUN Commands Reducing the number of layers will reduce the overall size of your image, even if the output is the same. COPY package.json /app/package.json RUN npm install && npm ls && npm cache clean --force && mv /app/node_modules /node_modules COPY . /app COPY package.json /app/package.json RUN npm install RUN npm ls RUN npm cache clean --force RUN mv /app/node_modules /node_modules COPY . /app 92MB83.9MB
  • 30. © 2018 All Rights Reserved. !30 Pick Base Images Wisely! By now, almost every major language or framework maintains a slim version of their library image, tagged with slim or specifically with alpine. Warning: the size of an image on Docker Hub is the compressed size. hub.docker.com/_/node
  • 31. © 2018 All Rights Reserved. !31 Avoid Anti-Patterns ‣ Simultaneous Innovation ‣ Skipping the fundamentals like giving love to your Dockerfiles ‣ Forgetting other development best practices like pinning dependencies to versions — this stuff still matters even if you’re using containers ‣ For example, don’t use the latest tag
  • 32. © 2018 All Rights Reserved. !32 Laura’s Model for Super Duper Container Success Get it running in a container. Create an application template and get that running. Then optimize your Dockerfile. Then worry about everything else.
  • 33. © 2018 All Rights Reserved. !33 3 DEBUGGING IN CONTAINERS
  • 34. © 2018 All Rights Reserved. !34 You can access log output either via Docker Compose or Docker directly. $ docker-compose logs # this returns all logs for all services db | LOG: stats_timestamp 2018-09-12 10:35:03.286676+00 is later than collector's time 2018-09-12 10:35:03.262932+00 for database 12141 result_1 | [nodemon] restarting due to changes... result_1 | [nodemon] starting `node --inspect=[::]:5858 server.js` result_1 | Debugger listening on ws://[::]:5858/f6dd534f-1976-421c-b4e2-8d3b1baf2622 result_1 | For help, see: https://nodejs.org/en/docs/inspector result_1 | App running on port 80 result_1 | Connected to db result_1 | Debugger attached. redis | 1:M 12 Sep 08:33:52.991 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. redis | 1:M 12 Sep 08:33:52.991 # Server initialized Viewing Log Output
  • 35. © 2018 All Rights Reserved. !35 Viewing Log Output Logs are visible by default when starting your app with docker-compose up. If you prefer a tidy terminal, use up with the detached flag. You can get logs per service later. Tip: timestamps are available with a flag. $ docker-compose up -d ... $ docker-compose logs -t worker # docker logs -t example-voting-app_worker_1 worker_1 | 2018-09-12T08:22:49.367373200Z Waiting for db worker_1 | 2018-09-12T08:22:50.371369500Z Waiting for db worker_1 | 2018-09-12T08:22:53.526120800Z Connected to db worker_1 | 2018-09-12T08:22:53.541336500Z Found redis at 172.20.0.2 worker_1 | 2018-09-12T08:22:53.541400100Z Connecting to redis worker_1 | 2018-09-12T08:33:54.478754500Z Connected to db worker_1 | 2018-09-12T08:33:54.495682400Z Found redis at 172.20.0.2 worker_1 | 2018-09-12T08:33:54.496062600Z Connecting to redis worker_1 | 2018-09-12T08:34:15.528315300Z Processing vote for 'b' by '2d4e42c6c94f4e53' worker_1 | 2018-09-12T08:37:11.883353600Z Processing vote for 'a' by ‘2d4e42c6c94f4e53'
  • 36. © 2018 All Rights Reserved. !36 Tip: set many options on Docker Compose directly, not on subcommands. --verbose Show more output --log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) Debugging Compose Itself
  • 37. © 2018 All Rights Reserved. !37 Starting a Container in Interactive Mode Want a shell to debug startup commands without the container exiting on failure? version: "3" services: web: image: ubuntu:18.04 tty: true stdin_open: true entrypoint: "/bin/bash" docker run -it ubuntu:18:04 /bin/bash # volume mount if you need to with `-v source:target` with docker-compose run web with Docker only
  • 38. © 2018 All Rights Reserved. !38 ‣ docker top will give you a list of all running processes in a container ‣ docker inspect (name|id) will give you ALL of the details about a given resource Helpful Docker Commands ‣ You can use the --format flag and pass in a Go template ‣ For example, to get the IP(s) of a running container: docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_ID
  • 39. © 2018 All Rights Reserved. !39 Running a Debugger version: "3" services: result: build: ./result command: nodemon --inspect=0.0.0.0:5858 server.js volumes: - ./result:/app ports: - “5001:80" - "5858:5858" networks: - front-tier - back-tier Maintain access to debugging tools by publishing the ports. You may also have to update the command or entrypoint to access debugging tools.
  • 40. © 2018 All Rights Reserved. !40
  • 41. Visit the CodeShip team at our booth!