Intro to Docker


https://slides.com/coreybrooks/intro-to-docker
whoami
corey@ondeck-ai.com
Github: c-Brooks
Software Engineer @OnDeck-AI
Previously @GitHub, @Gitalytics, @Foodee


Quick show of hands
- Experience with VMs?
- Experience with Docker?

🤚
Virtual Machines | Containers |
---|---|
Separate kernel for each VM | One kernel manages containers |

Source: https://www.smarthomebeginner.com/what-is-docker-docker-vs-virtualbox/

Virtual Machines | Containers |
---|---|
"House" | "Apartment Suite" |



VS

IMAGE
CONTAINER

IMAGE
.ISO FILE
CONTAINER
THE VM
VS

Container VS Image
IMAGE
CLASS
CONTAINER
INSTANCE OF CLASS
VS
Docker CLI
https://docs.docker.com/engine/reference/commandline/cli/
Commands:
build Build an image from a Dockerfile
commit Create a new image from a container's changes
exec Run a command in a running container
images List images
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more containers
run Run a command in a new container
help Show usage



DEMO TIME
🙏

NETWORKING
Docker Networking

docker network create my_net
docker run -d --network=my_net nginx
Docker Networking

docker network create my_net
docker run -d --network=my_net nginx
👎



TRAFFIC
LB
SERVER1
DB
"INTERNET"
DOCKER NETWORK
SERVER2

TRAFFIC
FRONTEND
NETWORK
INTERNET
LB
DB
BACKEND NETWORK
SERVER2
SERVER1


BEST PRACTICES
Dockerfiles

What is an image?



Docker's Build Cache

Docker's Build Cache
- COPY/ADD steps compare the host fs
- Other steps are always cached

Docker's Build Cache
# .dockerignore
# editor stuff
.idea/
.vscode/
.subl/
# dependencies
node_modules/
vendor/
# anything else...
Dockerfile
docker-compose.yaml
.dockerignore
Ignores everything for ADD/COPY steps
This will limit cache busting

Docker's Build Cache
FROM node:boron-jessie
ENV NODE_ENV=dev
WORKDIR /usr/app
ADD . /usr/app
RUN \
npm install
CMD ["node", "app.js"]
FROM node:boron-jessie
ENV NODE_ENV=dev
WORKDIR /usr/app
ADD package.json /usr/app/package.json
RUN \
npm install
ADD . /usr/app
CMD ["node", "app.js"]
BAD
GOOD

Minimizing Image Size

Minimizing Image Size
size = \Sigma(\Delta size_i)

Minimizing Image Size
size = \Sigma(\Delta size_i)
Delete useless files in the same RUN command

Minimizing Image Size
size = \Sigma(\Delta size_i)
Delete useless files in the same RUN command
Use Multi-Stage builds

Questions?
Intro to Docker
By Corey Brooks
Intro to Docker
- 542