SlideShare a Scribd company logo
Getting Started
with Docker
Michael Irwin
Developer Relations | Docker
2
00 Intro
Michael Irwin
Developer Relations | Docker
Interact with me @mikesir87
3
Group selfie!
#dockercon
00 Intro
4
Workshop agenda
8:00-8:40 Container and image intro
8:40-9:15 Using containers for development
9:15-9:30 Break
9:30-10:10 Building your own images
10:10-11:00 Multi-service applications
11:00-11:15 Break
11:15-12:00 Intro to Docker Compose
00 Intro
01 Container and image intro
6
This section’s learning objectives
● By the end of this section, you’ll be able to answer these questions:
○ What is a container? Image?
○ How’s a container different than a VM?
○ What is Docker’s current role in the container ecosystem?
○ Why should I care about this container movement?
○ How do I run a simple container? See what’s running? View logs?
01 Container and image intro
7
01 Container and image intro
Docker’s vision
Increase the time developers spend on innovation
and decrease the time they spend on everything else
8
01 Container and image intro
Welcome!
Glad to have
you on the
team!
We already
assigned you an
easy first task.
Challenge - see if
you can knock it
out by lunch!
9
01 Container and image intro
Welcome!
Glad to have
you on the
team!
Clone the repo, use
README to install
env. Spend the first
week updating the
docs and setting up
your machine. Then
work on the task
10
Wouldn’t it be
nice if we could
just run software,
without installing
or configuring it?
01 Container and image intro
11
01 Container and image intro
Vote webapp
(Python)
Queue
(Redis)
Database
(PostgreSQL)
Results webapp
(Node)
Worker
(.NET)
Example voting app: github.com/dockersamples/example-voting-app
Demo time!
12
Containers vs VMs
● Containers are…
○ Simply isolated processes, not full VMs
○ Much more portable than VMs
○ Using the same kernel as the host
○ Able to limit CPU/memory
● VMs are…
○ A full OS with kernel
○ A deeper level of isolation
○ Able to provide storage and
networking limits
01 Container and image intro
13
01 Container and image intro
14
01 Container and image intro
15
Are containers
just for
microservices?
01 Container and image intro
16
Docker Hub
● The default marketplace for images!
● Trusted Content
○ Docker Official Images
○ Verified Publishers
○ Sponsored Open Source Software
● Personal and organizational repos
01 Container and image intro
17
Docker Desktop
● The local install for everything Docker!
● Provides the ability to…
○ Run containerized workloads
○ Build images
○ Launch Kubernetes with one click
● Provides both CLI and GUI interfaces
● Works across Mac, Windows, and Linux
01 Container and image intro
18
Docker Scout
01 Container and image intro
● Provide developers with the tools
needed to build secure software
supply chains
○ Vulnerability information
○ Remediation recommendations
● Provide organizations with
understandings on what’s going on
with their images
19
Starting a container using the CLI
# Start a mongo container, named mongo, in the background
docker run --name mongo -d mongo
# Start an interactive ubuntu container and auto-remove it when it exits
docker run --rm -it ubuntu
# Start nginx and expose its web server port to the host
# The port mapping is [host port]:[container port]
docker run -d -p 80:80 nginx
01 Container and image intro
20
Explaining port mappings
● Every container gets its own IP address
● When a container uses a port, it’s only
listening on its IP address
● Exposing a port = create config to connect
the host network interfaces to the container
01 Container and image intro
docker run -p 80:80 --name nginx1 nginx
docker run -p 8080:80 --name nginx2 nginx
Host machine
nginx1
:80
:80
nginx2
:80
:8080
21
“Advanced” container starts
# Start a postgres container and specify the root user's password
docker run -d -e POSTGRES_PASSWORD=test postgres
# Adding labels to containers
docker run -d -p 80:80 --label app=sample-app --label component=website nginx
01 Container and image intro
22
Working with containers
# List running containers
docker ps
# List all running containers, filtering by a specific label
docker ps -a
# List all running containers, including stopped containers
docker ps --filter=label=app=sample-app
# Remove a container whose ID begins with abc (-f stops it first)
docker rm -f abc
01 Container and image intro
23
Troubleshooting/debugging containers
# Run a single process inside an existing container
docker exec <container-identifier> <command>
docker exec abc ls /usr/share/nginx/html
# Start an interactive shell inside a container
docker exec -ti abc bash
docker exec -ti abc sh
# View logs for a container
docker logs <container-id>
01 Container and image intro
HANDS-ON
TIME!!!
25
Hands-on instructions
1. Go to the workshop repo at
github.com/mikesir87/dockercon23-workshop-materials
2. Follow the README instructions to install the extension workshop
3. Open the extension and start with the
Running containers category
We’ll resume at 8:40.
01 Container and image intro
02Using containers for development
27
This section’s learning objectives
● By the end of this section, you’ll be able to answer these questions:
○ How can I use containers in local development?
○ How can I persist data created by containers?
○ How can I share my host files with a running container?
02 Using containers for development
28
Using containers in development
● There are several ways to use containers
○ Run dependent services
○ Test your applications
○ Provide the dev environment
○ And more!
02 Using containers for development
29
Containers
Run dependent services
● Keep doing development the way you’ve always done it
● Identify the dependent services and run those as containers
02 Using containers for development
Main application
MySQL database
Redis cache
30
Containers
Test your app with containers
● Build the container images locally to validate everything works
● Feedback loop = build a new image and restart the container with each
code change
02 Using containers for development
Main application
MySQL database
Redis cache
31
Containers
Develop in containers
● Use the container for the runtime environment and either share or sync file
changes into the container
● Feedback loop = immediate (or close to it)
02 Using containers for development
Main application
MySQL database
Redis cache
Application source
code
32
Volumes and bind mounts
● The container’s filesystem comes from the
image
● Bind mounts let us share files from the host
● Volumes let us persist data in the container
docker run -v mysql-data:/var/lib/mysql ... mysql
mysql
/var/lib/mysql
mysql-data
docker run -v ./src:/usr/share/nginx/html ... nginx
nginx
/usr/share/nginx/html
./src on host
02 Using containers for development
33
Working with volumes
# Create a named volume
docker volume create mysql-files
# List all volumes
docker volume ls
# Connect a volume to a container
docker run -v mysql-files:/var/lib/mysql ... mysql
# Remove a volume (only works if it’s not in use)
docker volume rm mysql-files
02 Using containers for development
34
Visualizing what’s in a volume
02 Using containers for development
HANDS-ON
TIME!!!
Work on the “Working
with volumes”
category
We’ll work until 9:15 and
then take a break until
9:30
03Building your own images
37
This section’s learning objectives
● By the end of this section, you’ll be able to answer these questions:
○ What actually is an image? What are image layers?
○ How can I see what’s in an image or how it was built?
○ What’s a Dockerfile and how do I use it to build an image?
○ How do I share my custom-built images?
03 Building your own images
38
When I pull
image, what’s
actually being
downloaded?
03 Building your own images
39
Image layering
● Images are composed of layers
● Each layer contains a set of filesystem changes
● See the layers by using the docker image history command
03 Building your own images
docker image history nginx
ADD files
CMD ["bash"]
COPY more files
COPY more files
COPY more files
Set default command and other config
This layer is also the
debian:12-slim image
40
Creating an image manually
● You can create your own image manually
○ Start a container with docker run
○ Make changes with docker cp or docker exec
○ Commit the changes using docker commit
03 Building your own images
41
Or script it!
● Build images using a Dockerfile
● Text-based file with instructions on how to build an image
○ FROM - the base image to start from
○ WORKDIR - set the working directory in the image
○ COPY - copy files from host into the image
○ RUN - run a command
○ EXPOSE - specify a port the container wants to use
○ CMD - set the default command
03 Building your own images
FROM node:lts
WORKDIR /usr/local/app
COPY package.json yarn.lock ./
RUN yarn install
COPY ./src ./src
EXPOSE 3000
CMD ["node", "src/index.js"]
42
Image naming
● Image names have several components, separated by slashes
03 Building your own images
my-registry.com/namespace/image-repository:tag
The registry this image
came from/will go to
(defaults to Docker Hub)
The namespace.
Typically a username,
org, or team name.
Can be multiple
segments.
The final image
repository
The image tag.
Can be different
versions, builds,
variants, etc.
43
Image naming examples
● alpine
○ Docker Hub; library namespace (Official Images); alpine image; latest tag
● mikesir87/cats:1.0
○ Docker Hub; mikesir87 namespace; cats image; 1.0 tag
● my-registry.com/org/webapp:3accda9
○ Registry at my-registry.com; org namespace; webapp image; 3accda9 tag
03 Building your own images
44
Building and pushing images
# Build an image using the Dockerfile in this directory and name the
# new image mikesir87/my-website. The mikesir87 portion is my Docker Hub
# username, so swap it out with your username
docker build -t mikesir87/my-website .
# Push the image to Docker Hub!
docker push mikesir87/my-website
03 Building your own images
45
A few build best practices
● Each container should do one thing and do it well
○ Avoid creating “general purpose” images
● Don’t ship dev tooling into production
○ Multi-stage image builds help tremendously here!
● Use or create trusted base images
○ Can leverage our Docker Official Images or build your own
● Pin your images (don’t use the default :latest tag)
○ FROM node -> FROM node:20.5-alpine3.17
○ Can pin to specific SHA sums too! FROM node@sha256:0b889cbf7…
03 Building your own images
HANDS-ON
TIME!!!
Work on the
“Building images”
category
We’ll resume at 10:10
04Multi-service applications
48
This section’s learning objectives
● By the end of this section, you’ll be able to answer these questions:
○ How can I allow containers to communicate with each other?
○ How can one container find another container?
○ How do I create and use networks and network aliases?
04 Multi-service applications
49
If each container
should do one
thing, how do we
connect them
together?
04 Multi-service applications
50
Network communication
● The network namespace gives…
○ Each container its own IP address
○ Its own loopback interface (localhost)
● Each containerized process listens on ports for its network interfaces
○ Remember port mappings?
Host machine
nginx1
:80
:80
nginx2
:80
:8080
04 Multi-service applications
51
Docker networks
● Any two containers on the same network can talk to each other
● Containers can be on multiple networks
● Create and manage networks with the docker network command
● Attach containers either at launch or later
04 Multi-service applications
app1 network
API Database
Cache
app2 network
API Database
Cache
52
Basic network commands
# Create a network named app
docker network create app
# Start a nginx container on the app network
docker run -d --network app nginx
# Connect an existing container, with id abcd1234, to the app network
docker network connect app abcd1234
04 Multi-service applications
53
Service discovery
● Containers can be given a “network alias”
● Effectively, this becomes a DNS name that will resolve only within the same
networks
04 Multi-service applications
app1 network
API Database
Cache
cache
db
54
Basic network commands
# Create a network named app
docker network create app
# Start a mysql container on the app network, given it an alias of db
docker run -d --network app --network-alias db ... mysql
# Connect an existing container, but give it a network alias
docker network connect --alias=cache app abcd1234
04 Multi-service applications
55
A few multi-service best practices
● Again… each container should do one thing and do it well
● Use service discovery to locate other dependencies
○ In Docker, that’s through the use of networks and network aliases
○ In Kubernetes, that’s through the use of Service objects
○ Many cloud provider container systems have DNS-based discovery mechanisms
04 Multi-service applications
HANDS-ON
TIME!!!
Work on the
“Multi-service
applications” category
Work until 11 and take a
break until 11:15
05Intro to Docker Compose
58
This section’s learning objectives
● By the end of this section, you’ll be able to answer these questions:
○ How do the Docker CLI and Engine interact?
○ What is Docker Compose?
○ How do I use Compose to launch applications?
○ How do I create my own Compose file?
○ What new things are going on with Compose?
05 Intro to Docker Compose
59
With networks,
volumes, and the
many flags of
containers, it’s
got to be easier
to define
everything, right?
05 Intro to Docker Compose
60
The Docker Engine
● The Docker Daemon/Engine
○ Manages everything
○ Exposes a REST API
● The Docker CLI
○ Interacts with the API
○ Provides a CLI-based user interface
○ Can be configured to point to remote engines
05 Intro to Docker Compose
61
The Engine API
● The API is documented online
● The API provides the ability to do anything on Docker daemon
○ Provides ability to build other tooling/automations on top of the engine
05 Intro to Docker Compose
62
The Goal
05 Intro to Docker Compose
1. git clone
2. docker compose up
3. Do cool stuff!
63
Basic Compose commands
# Use Compose to reconcile and launch what’s defined
docker compose up
# Tear everything down (leaves volumes by default)
docker compose down
# Share logs from all of the application services
docker compose logs
05 Intro to Docker Compose
64
Converting a docker run command
05 Intro to Docker Compose
docker run -d -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=test 
-e MYSQL_DATABASE=dev 
-v mysql-data:/var/lib/mysql 
mysql:8.0
65
Converting a docker run command
05 Intro to Docker Compose
docker run -d -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=test 
-e MYSQL_DATABASE=dev 
-v mysql-data:/var/lib/mysql 
mysql:8.0
services:
db:
image: mysql:8.0
The services represent each of the
building blocks of my application.
I define a service named db and
specify the container image it will
use.
66
Converting a docker run command
05 Intro to Docker Compose
docker run -d -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=test 
-e MYSQL_DATABASE=dev 
-v mysql-data:/var/lib/mysql 
mysql:8.0
services:
db:
image: mysql:8.0
ports:
- 3306:3306
Next, we bring over the port mapping.
The Compose specification has both a
short-form syntax and a long-form
syntax that’s more verbose.
services:
db:
image: mysql:8.0
ports:
- target: 3306
published: 3306
OR
67
Converting a docker run command
05 Intro to Docker Compose
docker run -d -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=test 
-e MYSQL_DATABASE=dev 
-v mysql-data:/var/lib/mysql 
mysql:8.0
services:
db:
image: mysql:8.0
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: dev
Next, we bring over the environment
variables.
The Compose specification allows you
to define them as either a key/value
mapping or as an array of KEY=VALUE
strings.
services:
db:
image: mysql:8.0
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=dev
OR
68
Converting a docker run command
05 Intro to Docker Compose
docker run -d -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=test 
-e MYSQL_DATABASE=dev 
-v mysql-data:/var/lib/mysql 
mysql:8.0
services:
db:
image: mysql:8.0
ports:
- 3306:3306
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: dev
volumes:
mysql-data:
Next, we define the volume, ensuring
our data is persisted across
environment restarts
69
Let’s launch it!
05 Intro to Docker Compose
70
Adding another service
05 Intro to Docker Compose
● With Compose, it’s easy to add other services to
help with debugging and troubleshooting
● This new service is adds a database visualizer
services:
db:
...
phpmyadmin:
image: phpmyadmin:5.2
ports:
- 8080:80
...
71
Using depends_on
05 Intro to Docker Compose
● Ensures the configured service doesn’t start until conditions are met
● The default condition is simple - the referenced service is up and running
● Other conditions provide for health checks passing or successful exits
services:
db:
...
phpmyadmin:
...
depends_on:
- db
...
services:
db:
...
phpmyadmin:
...
depends_on:
db:
condition: service_healthy
...
72
Compose networking
05 Intro to Docker Compose
● Each Compose stack gets its own
network
● Each service has a DNS entry added that
matches its name
○ The phpmyadmin service can connect to
the database using the name db
services:
db:
...
phpmyadmin:
image: phpmyadmin:5.2
ports:
- 8080:80
depends_on:
- db
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: test
...
73
Let’s launch it!
05 Intro to Docker Compose
74
Compose Watch
05 Intro to Docker Compose
● Watch for file changes and perform
actions
○ Sync files from host to container
○ Auto rebuild images and restart containers
● Available with the new docker compose
watch command
services:
...
client:
...
develop:
watch:
- path: ./client/src
action: sync
target: /usr/src/app/src
- path: ./client/yarn.lock
action: rebuild
...
75
Compose Watch
05 Intro to Docker Compose
● Include Compose files from other
locations for composable apps
○ Reference local files
○ Pull from remote git repos
● Each Compose file can reference their
own relative paths
include:
- another-compose.yaml
- git@github.com:namespace/repo.git
services:
...
volumes:
...
06Recap
77
What we covered
Container/image basics
What they are, why they matter, how
to think about them. How they’re
different than VMs.
How to run containers and how to
build your own images.
Multi-service applications
How to build container networks
and use DNS to provide service
discovery between containers.
Intro to Docker Compose
The tool that builds on the Docker
Engine to help your team be super
productive..
06 Recap
78
Welcome!
Glad to have
you on the
team!
We already
assigned you an
easy first task.
Challenge - see if
you can knock it
out by lunch!
06 Recap
79
Welcome!
Glad to have
you on the
team!
Well done! We knew
you had it in you and
glad to hear the
onboarding was easy!
Again… welcome
aboard!
06 Recap
80
Going forward
● Attend the keynotes and other sessions
● Join the Docker Community Slack (if you haven’t yet)
● Interact with the Docker roadmap (github.com/docker/roadmap)
06 Recap
Thank you!
Dockercon 23 - Getting started with Docker

More Related Content

PPTX
Containerization using docker and its applications
PPTX
Containerization using docker and its applications
PDF
Cloud Native Computing - Part III - Containers
PPTX
Introduction to automated environment management with Docker Containers - for...
PDF
docker.pdf
PPTX
Getting Started with Docker
PDF
Work shop - an introduction to the docker ecosystem
PDF
Introduction to Containers - From Docker to Kubernetes and everything in between
Containerization using docker and its applications
Containerization using docker and its applications
Cloud Native Computing - Part III - Containers
Introduction to automated environment management with Docker Containers - for...
docker.pdf
Getting Started with Docker
Work shop - an introduction to the docker ecosystem
Introduction to Containers - From Docker to Kubernetes and everything in between

Similar to Dockercon 23 - Getting started with Docker (20)

PPSX
Docker Kubernetes Istio
PPTX
Docker Kubernetes Istio
PDF
Docker
PPTX
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
PDF
Docker 101: An Introduction
PPTX
Java developer intro to environment management with vagrant puppet and docker
PDF
Introduction to Containers - From Docker to Kubernetes and everything in between
PDF
Docker, but what it is?
PDF
Containers: from development to production at DevNation 2015
PDF
Up and running with docker
PPTX
Novices guide to docker
PDF
Faster and Easier Software Development using Docker Platform
PPTX
Powercoders · Docker · Fall 2021.pptx
PPTX
Virtualization, Containers, Docker and scalable container management services
PDF
Introduction to Docker and Linux Containers @ Cloud Computing Rhein Main
PPTX
Docker 101
PDF
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
PDF
Can you contain the future - Docker, Container Technologies, The Future, and You
PPTX
Presentacio.pptx
PDF
codemotion-docker-2014
Docker Kubernetes Istio
Docker Kubernetes Istio
Docker
Java Developer Intro to Environment Management with Vagrant, Puppet, and Dock...
Docker 101: An Introduction
Java developer intro to environment management with vagrant puppet and docker
Introduction to Containers - From Docker to Kubernetes and everything in between
Docker, but what it is?
Containers: from development to production at DevNation 2015
Up and running with docker
Novices guide to docker
Faster and Easier Software Development using Docker Platform
Powercoders · Docker · Fall 2021.pptx
Virtualization, Containers, Docker and scalable container management services
Introduction to Docker and Linux Containers @ Cloud Computing Rhein Main
Docker 101
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Can you contain the future - Docker, Container Technologies, The Future, and You
Presentacio.pptx
codemotion-docker-2014
Ad

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Monthly Chronicles - July 2025
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Ad

Dockercon 23 - Getting started with Docker

  • 1. Getting Started with Docker Michael Irwin Developer Relations | Docker
  • 2. 2 00 Intro Michael Irwin Developer Relations | Docker Interact with me @mikesir87
  • 4. 4 Workshop agenda 8:00-8:40 Container and image intro 8:40-9:15 Using containers for development 9:15-9:30 Break 9:30-10:10 Building your own images 10:10-11:00 Multi-service applications 11:00-11:15 Break 11:15-12:00 Intro to Docker Compose 00 Intro
  • 5. 01 Container and image intro
  • 6. 6 This section’s learning objectives ● By the end of this section, you’ll be able to answer these questions: ○ What is a container? Image? ○ How’s a container different than a VM? ○ What is Docker’s current role in the container ecosystem? ○ Why should I care about this container movement? ○ How do I run a simple container? See what’s running? View logs? 01 Container and image intro
  • 7. 7 01 Container and image intro Docker’s vision Increase the time developers spend on innovation and decrease the time they spend on everything else
  • 8. 8 01 Container and image intro Welcome! Glad to have you on the team! We already assigned you an easy first task. Challenge - see if you can knock it out by lunch!
  • 9. 9 01 Container and image intro Welcome! Glad to have you on the team! Clone the repo, use README to install env. Spend the first week updating the docs and setting up your machine. Then work on the task
  • 10. 10 Wouldn’t it be nice if we could just run software, without installing or configuring it? 01 Container and image intro
  • 11. 11 01 Container and image intro Vote webapp (Python) Queue (Redis) Database (PostgreSQL) Results webapp (Node) Worker (.NET) Example voting app: github.com/dockersamples/example-voting-app Demo time!
  • 12. 12 Containers vs VMs ● Containers are… ○ Simply isolated processes, not full VMs ○ Much more portable than VMs ○ Using the same kernel as the host ○ Able to limit CPU/memory ● VMs are… ○ A full OS with kernel ○ A deeper level of isolation ○ Able to provide storage and networking limits 01 Container and image intro
  • 13. 13 01 Container and image intro
  • 14. 14 01 Container and image intro
  • 15. 15 Are containers just for microservices? 01 Container and image intro
  • 16. 16 Docker Hub ● The default marketplace for images! ● Trusted Content ○ Docker Official Images ○ Verified Publishers ○ Sponsored Open Source Software ● Personal and organizational repos 01 Container and image intro
  • 17. 17 Docker Desktop ● The local install for everything Docker! ● Provides the ability to… ○ Run containerized workloads ○ Build images ○ Launch Kubernetes with one click ● Provides both CLI and GUI interfaces ● Works across Mac, Windows, and Linux 01 Container and image intro
  • 18. 18 Docker Scout 01 Container and image intro ● Provide developers with the tools needed to build secure software supply chains ○ Vulnerability information ○ Remediation recommendations ● Provide organizations with understandings on what’s going on with their images
  • 19. 19 Starting a container using the CLI # Start a mongo container, named mongo, in the background docker run --name mongo -d mongo # Start an interactive ubuntu container and auto-remove it when it exits docker run --rm -it ubuntu # Start nginx and expose its web server port to the host # The port mapping is [host port]:[container port] docker run -d -p 80:80 nginx 01 Container and image intro
  • 20. 20 Explaining port mappings ● Every container gets its own IP address ● When a container uses a port, it’s only listening on its IP address ● Exposing a port = create config to connect the host network interfaces to the container 01 Container and image intro docker run -p 80:80 --name nginx1 nginx docker run -p 8080:80 --name nginx2 nginx Host machine nginx1 :80 :80 nginx2 :80 :8080
  • 21. 21 “Advanced” container starts # Start a postgres container and specify the root user's password docker run -d -e POSTGRES_PASSWORD=test postgres # Adding labels to containers docker run -d -p 80:80 --label app=sample-app --label component=website nginx 01 Container and image intro
  • 22. 22 Working with containers # List running containers docker ps # List all running containers, filtering by a specific label docker ps -a # List all running containers, including stopped containers docker ps --filter=label=app=sample-app # Remove a container whose ID begins with abc (-f stops it first) docker rm -f abc 01 Container and image intro
  • 23. 23 Troubleshooting/debugging containers # Run a single process inside an existing container docker exec <container-identifier> <command> docker exec abc ls /usr/share/nginx/html # Start an interactive shell inside a container docker exec -ti abc bash docker exec -ti abc sh # View logs for a container docker logs <container-id> 01 Container and image intro
  • 25. 25 Hands-on instructions 1. Go to the workshop repo at github.com/mikesir87/dockercon23-workshop-materials 2. Follow the README instructions to install the extension workshop 3. Open the extension and start with the Running containers category We’ll resume at 8:40. 01 Container and image intro
  • 26. 02Using containers for development
  • 27. 27 This section’s learning objectives ● By the end of this section, you’ll be able to answer these questions: ○ How can I use containers in local development? ○ How can I persist data created by containers? ○ How can I share my host files with a running container? 02 Using containers for development
  • 28. 28 Using containers in development ● There are several ways to use containers ○ Run dependent services ○ Test your applications ○ Provide the dev environment ○ And more! 02 Using containers for development
  • 29. 29 Containers Run dependent services ● Keep doing development the way you’ve always done it ● Identify the dependent services and run those as containers 02 Using containers for development Main application MySQL database Redis cache
  • 30. 30 Containers Test your app with containers ● Build the container images locally to validate everything works ● Feedback loop = build a new image and restart the container with each code change 02 Using containers for development Main application MySQL database Redis cache
  • 31. 31 Containers Develop in containers ● Use the container for the runtime environment and either share or sync file changes into the container ● Feedback loop = immediate (or close to it) 02 Using containers for development Main application MySQL database Redis cache Application source code
  • 32. 32 Volumes and bind mounts ● The container’s filesystem comes from the image ● Bind mounts let us share files from the host ● Volumes let us persist data in the container docker run -v mysql-data:/var/lib/mysql ... mysql mysql /var/lib/mysql mysql-data docker run -v ./src:/usr/share/nginx/html ... nginx nginx /usr/share/nginx/html ./src on host 02 Using containers for development
  • 33. 33 Working with volumes # Create a named volume docker volume create mysql-files # List all volumes docker volume ls # Connect a volume to a container docker run -v mysql-files:/var/lib/mysql ... mysql # Remove a volume (only works if it’s not in use) docker volume rm mysql-files 02 Using containers for development
  • 34. 34 Visualizing what’s in a volume 02 Using containers for development
  • 35. HANDS-ON TIME!!! Work on the “Working with volumes” category We’ll work until 9:15 and then take a break until 9:30
  • 37. 37 This section’s learning objectives ● By the end of this section, you’ll be able to answer these questions: ○ What actually is an image? What are image layers? ○ How can I see what’s in an image or how it was built? ○ What’s a Dockerfile and how do I use it to build an image? ○ How do I share my custom-built images? 03 Building your own images
  • 38. 38 When I pull image, what’s actually being downloaded? 03 Building your own images
  • 39. 39 Image layering ● Images are composed of layers ● Each layer contains a set of filesystem changes ● See the layers by using the docker image history command 03 Building your own images docker image history nginx ADD files CMD ["bash"] COPY more files COPY more files COPY more files Set default command and other config This layer is also the debian:12-slim image
  • 40. 40 Creating an image manually ● You can create your own image manually ○ Start a container with docker run ○ Make changes with docker cp or docker exec ○ Commit the changes using docker commit 03 Building your own images
  • 41. 41 Or script it! ● Build images using a Dockerfile ● Text-based file with instructions on how to build an image ○ FROM - the base image to start from ○ WORKDIR - set the working directory in the image ○ COPY - copy files from host into the image ○ RUN - run a command ○ EXPOSE - specify a port the container wants to use ○ CMD - set the default command 03 Building your own images FROM node:lts WORKDIR /usr/local/app COPY package.json yarn.lock ./ RUN yarn install COPY ./src ./src EXPOSE 3000 CMD ["node", "src/index.js"]
  • 42. 42 Image naming ● Image names have several components, separated by slashes 03 Building your own images my-registry.com/namespace/image-repository:tag The registry this image came from/will go to (defaults to Docker Hub) The namespace. Typically a username, org, or team name. Can be multiple segments. The final image repository The image tag. Can be different versions, builds, variants, etc.
  • 43. 43 Image naming examples ● alpine ○ Docker Hub; library namespace (Official Images); alpine image; latest tag ● mikesir87/cats:1.0 ○ Docker Hub; mikesir87 namespace; cats image; 1.0 tag ● my-registry.com/org/webapp:3accda9 ○ Registry at my-registry.com; org namespace; webapp image; 3accda9 tag 03 Building your own images
  • 44. 44 Building and pushing images # Build an image using the Dockerfile in this directory and name the # new image mikesir87/my-website. The mikesir87 portion is my Docker Hub # username, so swap it out with your username docker build -t mikesir87/my-website . # Push the image to Docker Hub! docker push mikesir87/my-website 03 Building your own images
  • 45. 45 A few build best practices ● Each container should do one thing and do it well ○ Avoid creating “general purpose” images ● Don’t ship dev tooling into production ○ Multi-stage image builds help tremendously here! ● Use or create trusted base images ○ Can leverage our Docker Official Images or build your own ● Pin your images (don’t use the default :latest tag) ○ FROM node -> FROM node:20.5-alpine3.17 ○ Can pin to specific SHA sums too! FROM node@sha256:0b889cbf7… 03 Building your own images
  • 46. HANDS-ON TIME!!! Work on the “Building images” category We’ll resume at 10:10
  • 48. 48 This section’s learning objectives ● By the end of this section, you’ll be able to answer these questions: ○ How can I allow containers to communicate with each other? ○ How can one container find another container? ○ How do I create and use networks and network aliases? 04 Multi-service applications
  • 49. 49 If each container should do one thing, how do we connect them together? 04 Multi-service applications
  • 50. 50 Network communication ● The network namespace gives… ○ Each container its own IP address ○ Its own loopback interface (localhost) ● Each containerized process listens on ports for its network interfaces ○ Remember port mappings? Host machine nginx1 :80 :80 nginx2 :80 :8080 04 Multi-service applications
  • 51. 51 Docker networks ● Any two containers on the same network can talk to each other ● Containers can be on multiple networks ● Create and manage networks with the docker network command ● Attach containers either at launch or later 04 Multi-service applications app1 network API Database Cache app2 network API Database Cache
  • 52. 52 Basic network commands # Create a network named app docker network create app # Start a nginx container on the app network docker run -d --network app nginx # Connect an existing container, with id abcd1234, to the app network docker network connect app abcd1234 04 Multi-service applications
  • 53. 53 Service discovery ● Containers can be given a “network alias” ● Effectively, this becomes a DNS name that will resolve only within the same networks 04 Multi-service applications app1 network API Database Cache cache db
  • 54. 54 Basic network commands # Create a network named app docker network create app # Start a mysql container on the app network, given it an alias of db docker run -d --network app --network-alias db ... mysql # Connect an existing container, but give it a network alias docker network connect --alias=cache app abcd1234 04 Multi-service applications
  • 55. 55 A few multi-service best practices ● Again… each container should do one thing and do it well ● Use service discovery to locate other dependencies ○ In Docker, that’s through the use of networks and network aliases ○ In Kubernetes, that’s through the use of Service objects ○ Many cloud provider container systems have DNS-based discovery mechanisms 04 Multi-service applications
  • 56. HANDS-ON TIME!!! Work on the “Multi-service applications” category Work until 11 and take a break until 11:15
  • 57. 05Intro to Docker Compose
  • 58. 58 This section’s learning objectives ● By the end of this section, you’ll be able to answer these questions: ○ How do the Docker CLI and Engine interact? ○ What is Docker Compose? ○ How do I use Compose to launch applications? ○ How do I create my own Compose file? ○ What new things are going on with Compose? 05 Intro to Docker Compose
  • 59. 59 With networks, volumes, and the many flags of containers, it’s got to be easier to define everything, right? 05 Intro to Docker Compose
  • 60. 60 The Docker Engine ● The Docker Daemon/Engine ○ Manages everything ○ Exposes a REST API ● The Docker CLI ○ Interacts with the API ○ Provides a CLI-based user interface ○ Can be configured to point to remote engines 05 Intro to Docker Compose
  • 61. 61 The Engine API ● The API is documented online ● The API provides the ability to do anything on Docker daemon ○ Provides ability to build other tooling/automations on top of the engine 05 Intro to Docker Compose
  • 62. 62 The Goal 05 Intro to Docker Compose 1. git clone 2. docker compose up 3. Do cool stuff!
  • 63. 63 Basic Compose commands # Use Compose to reconcile and launch what’s defined docker compose up # Tear everything down (leaves volumes by default) docker compose down # Share logs from all of the application services docker compose logs 05 Intro to Docker Compose
  • 64. 64 Converting a docker run command 05 Intro to Docker Compose docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=dev -v mysql-data:/var/lib/mysql mysql:8.0
  • 65. 65 Converting a docker run command 05 Intro to Docker Compose docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=dev -v mysql-data:/var/lib/mysql mysql:8.0 services: db: image: mysql:8.0 The services represent each of the building blocks of my application. I define a service named db and specify the container image it will use.
  • 66. 66 Converting a docker run command 05 Intro to Docker Compose docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=dev -v mysql-data:/var/lib/mysql mysql:8.0 services: db: image: mysql:8.0 ports: - 3306:3306 Next, we bring over the port mapping. The Compose specification has both a short-form syntax and a long-form syntax that’s more verbose. services: db: image: mysql:8.0 ports: - target: 3306 published: 3306 OR
  • 67. 67 Converting a docker run command 05 Intro to Docker Compose docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=dev -v mysql-data:/var/lib/mysql mysql:8.0 services: db: image: mysql:8.0 ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: test MYSQL_DATABASE: dev Next, we bring over the environment variables. The Compose specification allows you to define them as either a key/value mapping or as an array of KEY=VALUE strings. services: db: image: mysql:8.0 ports: - 3306:3306 environment: - MYSQL_ROOT_PASSWORD=test - MYSQL_DATABASE=dev OR
  • 68. 68 Converting a docker run command 05 Intro to Docker Compose docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=dev -v mysql-data:/var/lib/mysql mysql:8.0 services: db: image: mysql:8.0 ports: - 3306:3306 volumes: - mysql-data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: test MYSQL_DATABASE: dev volumes: mysql-data: Next, we define the volume, ensuring our data is persisted across environment restarts
  • 69. 69 Let’s launch it! 05 Intro to Docker Compose
  • 70. 70 Adding another service 05 Intro to Docker Compose ● With Compose, it’s easy to add other services to help with debugging and troubleshooting ● This new service is adds a database visualizer services: db: ... phpmyadmin: image: phpmyadmin:5.2 ports: - 8080:80 ...
  • 71. 71 Using depends_on 05 Intro to Docker Compose ● Ensures the configured service doesn’t start until conditions are met ● The default condition is simple - the referenced service is up and running ● Other conditions provide for health checks passing or successful exits services: db: ... phpmyadmin: ... depends_on: - db ... services: db: ... phpmyadmin: ... depends_on: db: condition: service_healthy ...
  • 72. 72 Compose networking 05 Intro to Docker Compose ● Each Compose stack gets its own network ● Each service has a DNS entry added that matches its name ○ The phpmyadmin service can connect to the database using the name db services: db: ... phpmyadmin: image: phpmyadmin:5.2 ports: - 8080:80 depends_on: - db environment: PMA_HOST: db PMA_USER: root PMA_PASSWORD: test ...
  • 73. 73 Let’s launch it! 05 Intro to Docker Compose
  • 74. 74 Compose Watch 05 Intro to Docker Compose ● Watch for file changes and perform actions ○ Sync files from host to container ○ Auto rebuild images and restart containers ● Available with the new docker compose watch command services: ... client: ... develop: watch: - path: ./client/src action: sync target: /usr/src/app/src - path: ./client/yarn.lock action: rebuild ...
  • 75. 75 Compose Watch 05 Intro to Docker Compose ● Include Compose files from other locations for composable apps ○ Reference local files ○ Pull from remote git repos ● Each Compose file can reference their own relative paths include: - another-compose.yaml - git@github.com:namespace/repo.git services: ... volumes: ...
  • 77. 77 What we covered Container/image basics What they are, why they matter, how to think about them. How they’re different than VMs. How to run containers and how to build your own images. Multi-service applications How to build container networks and use DNS to provide service discovery between containers. Intro to Docker Compose The tool that builds on the Docker Engine to help your team be super productive.. 06 Recap
  • 78. 78 Welcome! Glad to have you on the team! We already assigned you an easy first task. Challenge - see if you can knock it out by lunch! 06 Recap
  • 79. 79 Welcome! Glad to have you on the team! Well done! We knew you had it in you and glad to hear the onboarding was easy! Again… welcome aboard! 06 Recap
  • 80. 80 Going forward ● Attend the keynotes and other sessions ● Join the Docker Community Slack (if you haven’t yet) ● Interact with the Docker roadmap (github.com/docker/roadmap) 06 Recap