SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
Using Docker for
Development
@rhein_wein
Director of Engineering
CloudBees
Laura Frank Tacho
landscape.cncf.io
1 DOCKER COMPOSE BASICS
2 OPTIMIZING IMAGES
3 DEBUGGING IN CONTAINERS
1 DOCKER COMPOSE BASICS
Developer Tools
• Docker Compose
• Docker Desktop
• Docker for Mac
• Docker for Windows
• Easiest way to run Docker and Kubernetes on your local
machine
https://www.docker.com/products/docker-desktop
Sample App: Cats vs Dogs
vote result
github.com/rheinwein/example-voting-app
worker
.NET
vote
python
redis
redis
db
postgres
result
node-js
Sample App: Cats vs Dogs
github.com/rheinwein/example-voting-app
Use from DockerHub
Develop, build, and test
Sample App: Cats vs Dogs
github.com/rheinwein/example-voting-app
worker
.NET
vote
python
redis
redis
db
postgres
result
node-js
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
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
Text Editor
Container
Browser
Source Code
Access local code
See changes in the
browser immediately
Accessing Local 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
edit local code and have those
changes reflected in the
container
docker-compose.yml
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
You don’t need to run your
database in a container.
‣ 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
‣ 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
2 OPTIMIZING IMAGES
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.
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
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
For faster dev cycles, optimize
your images.
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
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
Dockerfile Best Practices with Tibor and Sebastiaan
Watch the recording when it’s available!
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
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
3 DEBUGGING IN CONTAINERS
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
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 -d 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'
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
‣ 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
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.
Visit the CodeShip team
at our booth!

Más contenido relacionado

La actualidad más candente

DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Waysmalltown
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandTroublemaker Khunpech
 
CI/CD (DevOps) 101
CI/CD (DevOps) 101CI/CD (DevOps) 101
CI/CD (DevOps) 101Hazzim Anaya
 
DevOps - an Agile Perspective (at Scale)
DevOps - an Agile Perspective (at Scale)DevOps - an Agile Perspective (at Scale)
DevOps - an Agile Perspective (at Scale)Brad Appleton
 
Docker introduction
Docker introductionDocker introduction
Docker introductiondotCloud
 
CI/CD Best Practices for Your DevOps Journey
CI/CD Best  Practices for Your DevOps JourneyCI/CD Best  Practices for Your DevOps Journey
CI/CD Best Practices for Your DevOps JourneyDevOps.com
 
Why Docker
Why DockerWhy Docker
Why DockerdotCloud
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker IntroductionPeng Xiao
 
Managing Infrastructure as a Product - Introduction to Platform Engineering
Managing Infrastructure as a Product - Introduction to Platform EngineeringManaging Infrastructure as a Product - Introduction to Platform Engineering
Managing Infrastructure as a Product - Introduction to Platform EngineeringAdityo Pratomo
 
Flusso Continuous Integration & Continuous Delivery
Flusso Continuous Integration & Continuous DeliveryFlusso Continuous Integration & Continuous Delivery
Flusso Continuous Integration & Continuous DeliveryJoost van der Griendt
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking OverviewSreenivas Makam
 
Présentation docker et kubernetes
Présentation docker et kubernetesPrésentation docker et kubernetes
Présentation docker et kubernetesKiwi Backup
 
Open Source Dev Containers with DevPod - Rich Burroughs.pdf
Open Source Dev Containers with DevPod - Rich Burroughs.pdfOpen Source Dev Containers with DevPod - Rich Burroughs.pdf
Open Source Dev Containers with DevPod - Rich Burroughs.pdfRich Burroughs
 
Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Amazon Web Services
 

La actualidad más candente (20)

DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
CI/CD (DevOps) 101
CI/CD (DevOps) 101CI/CD (DevOps) 101
CI/CD (DevOps) 101
 
DevOps - an Agile Perspective (at Scale)
DevOps - an Agile Perspective (at Scale)DevOps - an Agile Perspective (at Scale)
DevOps - an Agile Perspective (at Scale)
 
Docker Container Introduction
Docker Container IntroductionDocker Container Introduction
Docker Container Introduction
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
CI/CD Best Practices for Your DevOps Journey
CI/CD Best  Practices for Your DevOps JourneyCI/CD Best  Practices for Your DevOps Journey
CI/CD Best Practices for Your DevOps Journey
 
Why Docker
Why DockerWhy Docker
Why Docker
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
devops
devops devops
devops
 
Managing Infrastructure as a Product - Introduction to Platform Engineering
Managing Infrastructure as a Product - Introduction to Platform EngineeringManaging Infrastructure as a Product - Introduction to Platform Engineering
Managing Infrastructure as a Product - Introduction to Platform Engineering
 
Flusso Continuous Integration & Continuous Delivery
Flusso Continuous Integration & Continuous DeliveryFlusso Continuous Integration & Continuous Delivery
Flusso Continuous Integration & Continuous Delivery
 
Docker basics
Docker basicsDocker basics
Docker basics
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking Overview
 
Présentation docker et kubernetes
Présentation docker et kubernetesPrésentation docker et kubernetes
Présentation docker et kubernetes
 
Open Source Dev Containers with DevPod - Rich Burroughs.pdf
Open Source Dev Containers with DevPod - Rich Burroughs.pdfOpen Source Dev Containers with DevPod - Rich Burroughs.pdf
Open Source Dev Containers with DevPod - Rich Burroughs.pdf
 
Virtual Container - Docker
Virtual Container - Docker Virtual Container - Docker
Virtual Container - Docker
 
Multi Stage Docker Build
Multi Stage Docker Build Multi Stage Docker Build
Multi Stage Docker Build
 
Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration
 

Similar a DCEU 18: Developing with Docker Containers

Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For DevelopmentLaura Frank Tacho
 
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
 
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
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tipsSamuel Chow
 
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
 
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
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesSujay Pillai
 
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
 
Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peekmsyukor
 
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
 
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 TradeDocker, Inc.
 
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
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Ben Hall
 
Perspectives on Docker
Perspectives on DockerPerspectives on Docker
Perspectives on DockerRightScale
 
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 in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday developmentJustyna Ilczuk
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker composeLinkMe Srl
 
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
 
ContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessDocker-Hanoi
 

Similar a DCEU 18: Developing with Docker Containers (20)

Using Docker For Development
Using Docker For DevelopmentUsing Docker For Development
Using Docker For Development
 
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)
 
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
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
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
 
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
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content Services
 
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
 
Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peek
 
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
 
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
 
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
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016
 
Perspectives on Docker
Perspectives on DockerPerspectives on Docker
Perspectives on 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
 
Before & After Docker Init
Before & After Docker InitBefore & After Docker Init
Before & After Docker Init
 
Docker in everyday development
Docker in everyday developmentDocker in everyday development
Docker in everyday development
 
Adventures in docker compose
Adventures in docker composeAdventures in docker compose
Adventures in docker compose
 
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
 
ContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small business
 

Más de Docker, Inc.

Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Docker, Inc.
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildDocker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSDocker, Inc.
 
Securing Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXSecuring Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXDocker, Inc.
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeDocker, Inc.
 
Distributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDistributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDocker, Inc.
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubDocker, Inc.
 
Monitoring in a Microservices World
Monitoring in a Microservices WorldMonitoring in a Microservices World
Monitoring in a Microservices WorldDocker, Inc.
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...Docker, Inc.
 
Predicting Space Weather with Docker
Predicting Space Weather with DockerPredicting Space Weather with Docker
Predicting Space Weather with DockerDocker, Inc.
 
Become a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeBecome a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeDocker, Inc.
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryDocker, Inc.
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Docker, Inc.
 
Kubernetes at Datadog Scale
Kubernetes at Datadog ScaleKubernetes at Datadog Scale
Kubernetes at Datadog ScaleDocker, Inc.
 
Labels, Labels, Labels
Labels, Labels, Labels Labels, Labels, Labels
Labels, Labels, Labels Docker, Inc.
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelDocker, Inc.
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSDocker, Inc.
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...Docker, Inc.
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDocker, Inc.
 

Más de Docker, Inc. (20)

Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience Containerize Your Game Server for the Best Multiplayer Experience
Containerize Your Game Server for the Best Multiplayer Experience
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker Build
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
Securing Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINXSecuring Your Containerized Applications with NGINX
Securing Your Containerized Applications with NGINX
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and Compose
 
Hands-on Helm
Hands-on Helm Hands-on Helm
Hands-on Helm
 
Distributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at SalesforceDistributed Deep Learning with Docker at Salesforce
Distributed Deep Learning with Docker at Salesforce
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker Hub
 
Monitoring in a Microservices World
Monitoring in a Microservices WorldMonitoring in a Microservices World
Monitoring in a Microservices World
 
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
 
Predicting Space Weather with Docker
Predicting Space Weather with DockerPredicting Space Weather with Docker
Predicting Space Weather with Docker
 
Become a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio CodeBecome a Docker Power User With Microsoft Visual Studio Code
Become a Docker Power User With Microsoft Visual Studio Code
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container Registry
 
Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!Monolithic to Microservices + Docker = SDLC on Steroids!
Monolithic to Microservices + Docker = SDLC on Steroids!
 
Kubernetes at Datadog Scale
Kubernetes at Datadog ScaleKubernetes at Datadog Scale
Kubernetes at Datadog Scale
 
Labels, Labels, Labels
Labels, Labels, Labels Labels, Labels, Labels
Labels, Labels, Labels
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
 
Build & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWSBuild & Deploy Multi-Container Applications to AWS
Build & Deploy Multi-Container Applications to AWS
 
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
 
Developing with Docker for the Arm Architecture
Developing with Docker for the Arm ArchitectureDeveloping with Docker for the Arm Architecture
Developing with Docker for the Arm Architecture
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

DCEU 18: Developing with Docker Containers

  • 4. 1 DOCKER COMPOSE BASICS 2 OPTIMIZING IMAGES 3 DEBUGGING IN CONTAINERS
  • 6. Developer Tools • Docker Compose • Docker Desktop • Docker for Mac • Docker for Windows • Easiest way to run Docker and Kubernetes on your local machine https://www.docker.com/products/docker-desktop
  • 7. Sample App: Cats vs Dogs vote result github.com/rheinwein/example-voting-app
  • 9. Use from DockerHub Develop, build, and test Sample App: Cats vs Dogs github.com/rheinwein/example-voting-app worker .NET vote python redis redis db postgres result node-js
  • 10.
  • 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. 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. Text Editor Container Browser Source Code Access local code See changes in the browser immediately
  • 14. Accessing Local 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 edit local code and have those changes reflected in the container docker-compose.yml
  • 15.
  • 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. You don’t need to run your database in a container.
  • 18. ‣ 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 ‣ 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. 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.
  • 21. 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
  • 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"] 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
  • 23. For faster dev cycles, optimize your images.
  • 24. 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
  • 25. 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
  • 26. Dockerfile Best Practices with Tibor and Sebastiaan Watch the recording when it’s available!
  • 27. 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
  • 28. 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
  • 29. 3 DEBUGGING IN CONTAINERS
  • 30. 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
  • 31. 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 -d 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'
  • 32. 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
  • 33. ‣ 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
  • 34. 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.
  • 35.
  • 36. Visit the CodeShip team at our booth!