SlideShare uma empresa Scribd logo
1 de 74
Baixar para ler offline
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 1/74
Pruning
Cleaning Logs
Network Address Pools
Netshoot
Layers
BuildKit
Local Volume Driver
Fixing Permissions
Agenda
Tips and Tricks of the Docker Captains - @sudo_bmitch1 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 2/74
Brandon Mitchell
Twitter: @sudo_bmitch
GitHub: sudo-bmitch
Tips and Tricks
Of The Docker Captains
2 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 3/74
Pruning
Cleaning Logs
Network Address Pools
Netshoot
Layers
BuildKit
Local Volume Driver
Fixing Permissions
Agenda
Tips and Tricks of the Docker Captains - @sudo_bmitch3 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 4/74
$ whoami
Brandon Mitchell aka bmitch
- Solutions Architect @ BoxBoat
- Docker Captain
- Frequenter of StackOverflow
Tips and Tricks of the Docker Captains - @sudo_bmitch4 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 5/74
Who is a Developer?Who is a Developer?
Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch5 / 745 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 6/74
Disk Usage
Tips and Tricks of the Docker Captains - @sudo_bmitch6 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 7/74
Prune
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Tips and Tricks of the Docker Captains - @sudo_bmitch7 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 8/74
Prune
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
What this doesn't clean by default:
Running containers (and their logs)
Tagged images
Volumes
Tips and Tricks of the Docker Captains - @sudo_bmitch8 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 9/74
Prune ­ YOLO
$ docker run -d --restart=unless-stopped --name cleanup 
-v /var/run/docker.sock:/var/run/docker.sock
docker /bin/sh -c 
"while true; do docker system prune -f; sleep 1h; done"
Tips and Tricks of the Docker Captains - @sudo_bmitch9 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 10/74
Prune ­ YOLO
$ docker run -d --restart=unless-stopped --name cleanup 
-v /var/run/docker.sock:/var/run/docker.sock
docker /bin/sh -c 
"while true; do docker system prune -f; sleep 1h; done"
$ docker service create --mode global --name cleanup 
--mount type=bind,src=/var/run/docker.sock,
dst=/var/run/docker.sock 
docker /bin/sh -c 
"while true; do docker system prune -f; sleep 1h; done"
Tips and Tricks of the Docker Captains - @sudo_bmitch10 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 11/74
Container Logs
Tips and Tricks of the Docker Captains - @sudo_bmitch11 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 12/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
12 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 13/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
13 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 14/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
14 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 15/74
Clean Your Logs
$ cat docker-compose.yml
version: '3.7'
services:
app:
image: sudobmitch/loggen
command: [ "150", "180" ]
logging:
options:
max-size: "10m"
max-file: "3"
Tips and Tricks of the Docker Captains - @sudo_bmitch15 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 16/74
Clean Your Logs
version: '3.7'
x-defaults:
service: &default-svc
image: sudobmitch/loggen
logging: { options: { max-size: "10m", max-file: "3" } }
services:
cat:
<<: *default-svc
command: [ "300", "120" ]
environment: { pet: "cat" }
turtle:
<<: *default-svc
labels: { name: "gordon", levels: "all the way down" }
Tips and Tricks of the Docker Captains - @sudo_bmitch16 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 17/74
Clean Your Logs
Best option to prevent container logs from filling disk space
$ cat /etc/docker/daemon.json
{
"log-driver": "local",
"log-opts": {"max-size": "10m", "max-file": "3"}
}
$ systemctl reload docker
Tips and Tricks of the Docker Captains - @sudo_bmitch17 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 18/74
Tips and Tricks of the Docker Captains - @sudo_bmitch18 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 19/74
Tips and Tricks of the Docker Captains - @sudo_bmitch19 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 20/74
Networking
Tips and Tricks of the Docker Captains - @sudo_bmitch20 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 21/74
Subnet Collisions
Docker networks sometimes conflict with other networks
Tips and Tricks of the Docker Captains - @sudo_bmitch21 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 22/74
Subnet Collisions
Docker networks sometimes conflict with other networks
BIP, bridge network named "bridge"
$ cat /etc/docker/daemon.json
{
"bip": "10.15.0.1/24"
}
Tips and Tricks of the Docker Captains - @sudo_bmitch22 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 23/74
Subnet Collisions
Default address poll added in 18.06
$ cat /etc/docker/daemon.json
{
"bip": "10.15.0.1/24",
"default-address-pools": [
{"base": "10.20.0.0/16", "size": 24},
{"base": "10.40.0.0/16", "size": 24}
]
}
Tips and Tricks of the Docker Captains - @sudo_bmitch23 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 24/74
Subnet Collisions
$ docker swarm init --help
...
--default-addr-pool ipNetSlice
--default-addr-pool-mask-length uint32
Tips and Tricks of the Docker Captains - @sudo_bmitch24 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 25/74
Subnet Collisions
$ docker swarm init --help
...
--default-addr-pool ipNetSlice
--default-addr-pool-mask-length uint32
$ docker swarm init 
--default-addr-pool 10.20.0.0/16 
--default-addr-pool 10.40.0.0/16 
--default-addr-pool-mask-length 24
Tips and Tricks of the Docker Captains - @sudo_bmitch25 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 26/74
Network Debugging
Debugging networks from the host doesn't see inside the container namespace
Debugging inside the container means installing tools inside that container
Tips and Tricks of the Docker Captains - @sudo_bmitch26 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 27/74
Network Debugging
Debugging networks from the host doesn't see inside the container namespace
Debugging inside the container means installing tools inside that container
Sidecars aren't just for Kubernetes
Tips and Tricks of the Docker Captains - @sudo_bmitch27 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 28/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
28 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 29/74
Network Debugging
$ docker run --name web -p 9999:80 -d nginx
$ docker run -it --rm --net container:web 
nicolaka/netshoot ss -lnt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
Tips and Tricks of the Docker Captains - @sudo_bmitch29 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 30/74
Layered Filesystem
Tips and Tricks of the Docker Captains - @sudo_bmitch30 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 31/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
31 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 32/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
32 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 33/74
Understanding Layers
$ docker image build --rm=false --no-cache .
$ docker container diff ...
Tips and Tricks of the Docker Captains - @sudo_bmitch33 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 34/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
34 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 35/74
Understanding Layers
Delete temporary file in the same step where they are created
Small changes to big files are big changes
Merge your RUN commands together
Tips and Tricks of the Docker Captains - @sudo_bmitch35 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 36/74
From Bad ...
FROM golang:1.11
RUN adduser --disabled-password --gecos appuser appuser
WORKDIR /src
COPY . /src/
RUN go build -o app .
WORKDIR /
RUN cp /src/app /app
RUN chown appuser /app
RUN chmod 755 /app
RUN rm -r /src
USER appuser
CMD /app
Tips and Tricks of the Docker Captains - @sudo_bmitch36 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 37/74
... to Okay
FROM golang:1.11
RUN adduser --disabled-password --gecos appuser appuser
COPY . /src/
RUN cd /src 
&& go build -o app . 
&& cd / 
&& cp /src/app /app 
&& chown appuser /app 
&& chmod 755 /app 
&& rm -r /go/pkg /root/.cache/go-build /src
USER appuser
CMD /app
Tips and Tricks of the Docker Captains - @sudo_bmitch37 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 38/74
Multi­stage Builds
Everything we learned about making efficient images is now wrong
Build stage splits RUN lines to maximize caching
Only the released stage needs to be layer efficient
Tips and Tricks of the Docker Captains - @sudo_bmitch38 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 39/74
FROM golang:1.11-alpine as build
RUN apk add --no-cache git ca-certificates
RUN adduser -D appuser
WORKDIR /src
COPY . /src/
RUN CGO_ENABLED=0 go build -o app .
FROM scratch as release
COPY --from=build /etc/passwd /etc/group /etc/
COPY --from=build /src/app /app
USER appuser
CMD [ "/app" ]
FROM alpine as dev
COPY --from=build /src/app /app
CMD [ "/app" ]
FROM release
Tips and Tricks of the Docker Captains - @sudo_bmitch39 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 40/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
40 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 41/74
"Hold my beer.""Hold my beer."
­­BuildKit­­BuildKit
Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch41 / 7441 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 42/74
BuildKit Features For Everyone
GA in Docker 18.09
Context only pulls needed files
Multi-stage builds use a dependency graph
Cache from a remote registry
Pruning has options for cache age and size to keep
Tips and Tricks of the Docker Captains - @sudo_bmitch42 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 43/74
BuildKit Cache Pruning
$ docker builder prune --keep-storage=1GB --filter until=72h
Tips and Tricks of the Docker Captains - @sudo_bmitch43 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 44/74
BuildKit Cache Pruning
$ docker builder prune --keep-storage=1GB --filter until=72h
$ cat /etc/docker/daemon.json
{
"builder": {
"gc": {
"enabled": true,
"policy": [
{"keepStorage": "512MB", "filter": ["unused-for=168h"]]},
{"keepStorage": "30GB", "all": true}
]
} } }
Tips and Tricks of the Docker Captains - @sudo_bmitch44 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 45/74
BuildKit Experimental Features
Frontend parser can be changed
Bind Mounts, from build context or another image
Cache Mounts, similar to a named volume
Tmpfs Mounts
Build Secrets, file never written to image filesystem
SSH Agent, private Git repos
Tips and Tricks of the Docker Captains - @sudo_bmitch45 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 46/74
# syntax=docker/dockerfile:experimental
FROM golang:1.11-alpine as build
RUN apk add --no-cache git ca-certificates tzdata
RUN adduser -D appuser
WORKDIR /src
COPY . /src/
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod/cache 
--mount=type=cache,id=goroot,target=/root/.cache/go-build 
CGO_ENABLED=0 go build -o app .
USER appuser
CMD ./app
Tips and Tricks of the Docker Captains - @sudo_bmitch46 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 47/74
Tips and Tricks of the Docker Captains - @sudo_bmitch
00:00
47 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 48/74
Enable BuildKit
$ export DOCKER_BUILDKIT=1
$ docker build -t your_image .
Tips and Tricks of the Docker Captains - @sudo_bmitch48 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 49/74
Enable BuildKit
$ export DOCKER_BUILDKIT=1
$ docker build -t your_image .
$ cat /etc/docker/daemon.json
{ "features": {"buildkit": true} }
Tips and Tricks of the Docker Captains - @sudo_bmitch49 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 50/74
Volumes
Tips and Tricks of the Docker Captains - @sudo_bmitch50 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 51/74
Local Volume Driver
Tips and Tricks of the Docker Captains - @sudo_bmitch51 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 52/74
NFS Mounts
$ docker volume create 
--driver local 
--opt type=nfs 
--opt o=nfsvers=4,addr=nfs.example.com,rw 
--opt device=:/path/on/server 
foo
Tips and Tricks of the Docker Captains - @sudo_bmitch52 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 53/74
NFS Mounts
version: '3.7'
volumes:
nfs-data:
driver: local
driver_opts:
type: nfs
o: nfsvers=4,addr=nfs.example.com,rw
device: ":/path/to/dir"
services:
app:
volumes:
- nfs-data:/data
...
Tips and Tricks of the Docker Captains - @sudo_bmitch53 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 54/74
Other Filesystem Mounts
version: '3.7'
volumes:
ext-data:
driver: local
driver_opts:
type: ext4
o: ro
device: "/dev/sdb1"
services:
app:
volumes:
- ext-data:/data
...
Tips and Tricks of the Docker Captains - @sudo_bmitch54 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 55/74
Overlay Filesystem as a Volume
version: '3.7'
volumes:
overlay-data:
driver: local
driver_opts:
type: overlay
device: overlay
o: lowerdir=${PWD}/data2:${PWD}/data1,
upperdir=${PWD}/upper,workdir=${PWD}/workdir
services:
app:
volumes:
- overlay-data:/data
...
Tips and Tricks of the Docker Captains - @sudo_bmitch55 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 56/74
Named Bind Mount
version: '3.7'
volumes:
bind-vol:
driver: local
driver_opts:
type: none
o: bind
device: /home/user/host-dir
services:
app:
volumes:
- "bind-vol:/container-dir"
- "./code:/code"
...
Tips and Tricks of the Docker Captains - @sudo_bmitch56 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 57/74
That's nice, but I just use:That's nice, but I just use:
$(pwd)/code:/code$(pwd)/code:/code
Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch57 / 7457 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 58/74
That's nice, but I just use:That's nice, but I just use:
$(pwd)/code:/code$(pwd)/code:/code
"$(pwd)/code:/code""$(pwd)/code:/code"
Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch58 / 7458 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 59/74
Dockerfile for Java
FROM openjdk:jdk as build
RUN apt-get update 
&& apt-get install -y maven 
&& useradd -m app
COPY code /code
RUN mvn build
CMD ["java", "-jar", "/code/app.jar"]
USER app
FROM openjdk:jre as release
RUN useradd -m app
COPY --from=build /code/app.jar /app.jar
CMD ["java", "-jar", "/app.jar"]
USER app
Tips and Tricks of the Docker Captains - @sudo_bmitch59 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 60/74
Developer Compose File
version: '3.7'
volumes:
m2:
services:
app:
build:
context: .
target: build
image: registry:5000/app/app:dev
command: "/bin/sh -c 'mvn build && java -jar /code/app.jar'"
volumes:
- m2:/home/app/.m2
- ./code:/code
Tips and Tricks of the Docker Captains - @sudo_bmitch60 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 61/74
Problem with the Developer Workflow
Error accessing /code: permission denied
Tips and Tricks of the Docker Captains - @sudo_bmitch61 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 62/74
Problem with the Developer Workflow
Error accessing /code: permission denied
UID for app inside the container doesn't match our UID on the host
Tips and Tricks of the Docker Captains - @sudo_bmitch62 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 63/74
Problem with the Developer Workflow
Error accessing /code: permission denied
UID for app inside the container doesn't match our UID on the host
Unless you're on MacOS or VirtualBox
Tips and Tricks of the Docker Captains - @sudo_bmitch63 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 64/74
Fixing UID/GID
Possible solutions:
Run everything as root
Change permissions to 777
Adjust each developers uid/gid to match image
Adjust image uid/gid to match developers
Change the container uid/gid from run or compose
Tips and Tricks of the Docker Captains - @sudo_bmitch64 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 65/74
Fixing UID/GID
Possible bad solutions:
Run everything as root
Change permissions to 777
Adjust each developers uid/gid to match image
Adjust image uid/gid to match developers
Change the container uid/gid from run or compose
Tips and Tricks of the Docker Captains - @sudo_bmitch65 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 66/74
Fixing UID/GID
Possible bad solutions:
Run everything as root
Change permissions to 777
Adjust each developers uid/gid to match image
Adjust image uid/gid to match developers
Change the container uid/gid from run or compose
Another solution:
"Use a shell script" - Some Ops Guy
Tips and Tricks of the Docker Captains - @sudo_bmitch66 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 67/74
DisclaimerDisclaimer
The following slide may not be suitable for all audiencesThe following slide may not be suitable for all audiences
Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch67 / 7467 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 68/74
Fixing UID/GID: fix­perms
# update the uid
if [ -n "$opt_u" ]; then
OLD_UID=$(getent passwd "${opt_u}" | cut -f3 -d:)
NEW_UID=$(stat -c "%u" "$1")
if [ "$OLD_UID" != "$NEW_UID" ]; then
echo "Changing UID of $opt_u from $OLD_UID to $NEW_UID"
usermod -u "$NEW_UID" -o "$opt_u"
if [ -n "$opt_r" ]; then
find / -xdev -user "$OLD_UID" -exec chown -h "$opt_u" {} ;
fi
fi
fi
Tips and Tricks of the Docker Captains - @sudo_bmitch68 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 69/74
Fixing UID/GID: Dockerfile
FROM openjdk:jdk as build
COPY --from=sudobmitch/base:scratch / /
RUN apt-get update 
&& apt-get install -y maven 
&& useradd -m app
COPY code /code
RUN mvn build
COPY entrypoint.sh /usr/bin/
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["java", "-jar", "/code/app.jar"]
USER app
Tips and Tricks of the Docker Captains - @sudo_bmitch69 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 70/74
Fixing UID/GID: entrypoint.sh
#!/bin/sh
if [ "$(id -u)" = "0" ]; then
# running on a developer laptop as root
fix-perms -r -u app -g app /code
exec gosu app "$@"
else
# running in production as a user
exec "$@"
fi
Tips and Tricks of the Docker Captains - @sudo_bmitch70 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 71/74
Fixing UID/GID: Developer Compose File
version: '3.7'
volumes:
m2:
services:
app:
build:
context: .
target: build
image: registry:5000/app/app:dev
command: "/bin/sh -c 'mvn build && java -jar /code/app.jar'"
user: "0:0"
volumes:
- m2:/home/app/.m2
- ./code:/code
Tips and Tricks of the Docker Captains - @sudo_bmitch71 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 72/74
Fixing UID/GID: Production Compose File
version: '3.7'
services:
app:
image: registry:5000/app/app:${build_num}
Tips and Tricks of the Docker Captains - @sudo_bmitch72 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 73/74
Fixing UID/GID: Recap
Developers:
Mount code as from the host
Container starts entrypoint as root
Entrypoint changes uid of app user to match uid of /code
Entrypoint switches from root to app
Pid 1 is the app with a uid matching the host
Reads and writes to /code happen as the developers uid
Production:
Runs without root or a volume
Entrypoint skips fix-perms and gosu
Tips and Tricks of the Docker Captains - @sudo_bmitch73 / 74
5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell
https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 74/74
Brandon Mitchell
Twitter: @sudo_bmitch
GitHub: sudo-bmitch
Thank You
Rate this session in the DockerCon App
github.com/sudo-bmitch/presentations
github.com/sudo-bmitch/docker-base
74 / 74

Mais conteúdo relacionado

Mais procurados

파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Composeraccoony
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsBen Hall
 
手把手帶你學Docker 03042017
手把手帶你學Docker 03042017手把手帶你學Docker 03042017
手把手帶你學Docker 03042017Paul Chao
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境謝 宗穎
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with dockerGiacomo Bagnoli
 
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)Ruoshi Ling
 
Docker 初探,實驗室中的運貨鯨
Docker 初探,實驗室中的運貨鯨Docker 初探,實驗室中的運貨鯨
Docker 初探,實驗室中的運貨鯨Ruoshi Ling
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Bo-Yi Wu
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in descriptionPrzemyslaw Koltermann
 
Running .NET on Docker
Running .NET on DockerRunning .NET on Docker
Running .NET on DockerBen Hall
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationBen Hall
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersBen Hall
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよYusuke Kon
 
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
 
Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Paul Chao
 
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Docker Warsaw Meetup 12/2017 - DockerCon 2017 RecapDocker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Docker Warsaw Meetup 12/2017 - DockerCon 2017 RecapKrzysztof Sobczak
 
Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersBen Hall
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleRoman Rodomansky
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 applicationRoman Rodomansky
 

Mais procurados (20)

파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
 
Real World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js ApplicationsReal World Lessons on the Pain Points of Node.js Applications
Real World Lessons on the Pain Points of Node.js Applications
 
手把手帶你學Docker 03042017
手把手帶你學Docker 03042017手把手帶你學Docker 03042017
手把手帶你學Docker 03042017
 
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
Docker summit 2015: 以 Docker Swarm 打造多主機叢集環境
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with docker
 
Docker as an every day work tool
Docker as an every day work toolDocker as an every day work tool
Docker as an every day work tool
 
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
當專案漸趕,當遷移也不再那麼難 (Ship Your Projects with Docker EcoSystem)
 
Docker 初探,實驗室中的運貨鯨
Docker 初探,實驗室中的運貨鯨Docker 初探,實驗室中的運貨鯨
Docker 初探,實驗室中的運貨鯨
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署
 
Check the version with fixes. Link in description
Check the version with fixes. Link in descriptionCheck the version with fixes. Link in description
Check the version with fixes. Link in description
 
Running .NET on Docker
Running .NET on DockerRunning .NET on Docker
Running .NET on Docker
 
Real World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS ApplicationReal World Lessons on the Pain Points of Node.JS Application
Real World Lessons on the Pain Points of Node.JS Application
 
Lessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containersLessons from running potentially malicious code inside containers
Lessons from running potentially malicious code inside containers
 
Docker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよDocker composeで開発環境をメンバに配布せよ
Docker composeで開発環境をメンバに配布せよ
 
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
 
Docker workshop 0507 Taichung
Docker workshop 0507 Taichung Docker workshop 0507 Taichung
Docker workshop 0507 Taichung
 
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Docker Warsaw Meetup 12/2017 - DockerCon 2017 RecapDocker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
 
Lessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containersLessons from running potentially malicious code inside Docker containers
Lessons from running potentially malicious code inside Docker containers
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with Ansible
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 

Semelhante a DCSF19 Tips and Tricks of the Docker Captains

DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDocker, Inc.
 
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.
 
Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6LetsConnect
 
Build and run embedded apps faster from qt creator with docker
Build and run embedded apps faster from qt creator with dockerBuild and run embedded apps faster from qt creator with docker
Build and run embedded apps faster from qt creator with dockerQt
 
Webinar: Building Embedded Applications from QtCreator with Docker
Webinar: Building Embedded Applications from QtCreator with DockerWebinar: Building Embedded Applications from QtCreator with Docker
Webinar: Building Embedded Applications from QtCreator with DockerBurkhard Stubert
 
AtlasCamp 2015 Docker continuous integration training
AtlasCamp 2015 Docker continuous integration trainingAtlasCamp 2015 Docker continuous integration training
AtlasCamp 2015 Docker continuous integration trainingSteve Smith
 
DevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfDevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfkanedafromparis
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Jian-Hong Pan
 
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
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabMichelle Holley
 
Docker in Production: Reality, Not Hype
Docker in Production: Reality, Not HypeDocker in Production: Reality, Not Hype
Docker in Production: Reality, Not Hypebridgetkromhout
 
DeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to DockerDeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to DockerSteve Smith
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with DockerDocker, Inc.
 
Dockerize a Django app elegantly
Dockerize a Django app elegantlyDockerize a Django app elegantly
Dockerize a Django app elegantlyfrentrup
 
Mastering Docker on a Raspberry Pi
Mastering Docker on a Raspberry PiMastering Docker on a Raspberry Pi
Mastering Docker on a Raspberry PiTeam Hypriot
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverbridgetkromhout
 
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -EssentialsJAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentialsjazoon13
 
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015Jonas Rosland
 

Semelhante a DCSF19 Tips and Tricks of the Docker Captains (20)

DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker Captains
 
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
 
Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6Installing Component Pack 6.0.0.6
Installing Component Pack 6.0.0.6
 
Cloud RPI4 tomcat ARM64
Cloud RPI4 tomcat ARM64Cloud RPI4 tomcat ARM64
Cloud RPI4 tomcat ARM64
 
Optimizing Your CI Pipelines
Optimizing Your CI PipelinesOptimizing Your CI Pipelines
Optimizing Your CI Pipelines
 
Build and run embedded apps faster from qt creator with docker
Build and run embedded apps faster from qt creator with dockerBuild and run embedded apps faster from qt creator with docker
Build and run embedded apps faster from qt creator with docker
 
Webinar: Building Embedded Applications from QtCreator with Docker
Webinar: Building Embedded Applications from QtCreator with DockerWebinar: Building Embedded Applications from QtCreator with Docker
Webinar: Building Embedded Applications from QtCreator with Docker
 
AtlasCamp 2015 Docker continuous integration training
AtlasCamp 2015 Docker continuous integration trainingAtlasCamp 2015 Docker continuous integration training
AtlasCamp 2015 Docker continuous integration training
 
DevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdfDevOpSec_DockerNPodMan-20230220.pdf
DevOpSec_DockerNPodMan-20230220.pdf
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
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)
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 
Docker in Production: Reality, Not Hype
Docker in Production: Reality, Not HypeDocker in Production: Reality, Not Hype
Docker in Production: Reality, Not Hype
 
DeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to DockerDeveloperWeek 2015: A Practical Introduction to Docker
DeveloperWeek 2015: A Practical Introduction to Docker
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
 
Dockerize a Django app elegantly
Dockerize a Django app elegantlyDockerize a Django app elegantly
Dockerize a Django app elegantly
 
Mastering Docker on a Raspberry Pi
Mastering Docker on a Raspberry PiMastering Docker on a Raspberry Pi
Mastering Docker on a Raspberry Pi
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFever
 
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -EssentialsJAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
JAZOON'13 - Thomas Hug & Bartosz Majsak - Git Workshop -Essentials
 
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
 

Mais 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.
 
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.
 
Sharing is Caring: How to Begin Speaking at Conferences
Sharing is Caring: How to Begin Speaking at ConferencesSharing is Caring: How to Begin Speaking at Conferences
Sharing is Caring: How to Begin Speaking at ConferencesDocker, Inc.
 

Mais 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
 
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
 
Sharing is Caring: How to Begin Speaking at Conferences
Sharing is Caring: How to Begin Speaking at ConferencesSharing is Caring: How to Begin Speaking at Conferences
Sharing is Caring: How to Begin Speaking at Conferences
 

Último

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
[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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

DCSF19 Tips and Tricks of the Docker Captains

  • 1. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 1/74 Pruning Cleaning Logs Network Address Pools Netshoot Layers BuildKit Local Volume Driver Fixing Permissions Agenda Tips and Tricks of the Docker Captains - @sudo_bmitch1 / 74
  • 2. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 2/74 Brandon Mitchell Twitter: @sudo_bmitch GitHub: sudo-bmitch Tips and Tricks Of The Docker Captains 2 / 74
  • 3. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 3/74 Pruning Cleaning Logs Network Address Pools Netshoot Layers BuildKit Local Volume Driver Fixing Permissions Agenda Tips and Tricks of the Docker Captains - @sudo_bmitch3 / 74
  • 4. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 4/74 $ whoami Brandon Mitchell aka bmitch - Solutions Architect @ BoxBoat - Docker Captain - Frequenter of StackOverflow Tips and Tricks of the Docker Captains - @sudo_bmitch4 / 74
  • 5. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 5/74 Who is a Developer?Who is a Developer? Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch5 / 745 / 74
  • 6. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 6/74 Disk Usage Tips and Tricks of the Docker Captains - @sudo_bmitch6 / 74
  • 7. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 7/74 Prune $ docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all build cache Tips and Tricks of the Docker Captains - @sudo_bmitch7 / 74
  • 8. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 8/74 Prune $ docker system prune WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all build cache What this doesn't clean by default: Running containers (and their logs) Tagged images Volumes Tips and Tricks of the Docker Captains - @sudo_bmitch8 / 74
  • 9. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 9/74 Prune ­ YOLO $ docker run -d --restart=unless-stopped --name cleanup -v /var/run/docker.sock:/var/run/docker.sock docker /bin/sh -c "while true; do docker system prune -f; sleep 1h; done" Tips and Tricks of the Docker Captains - @sudo_bmitch9 / 74
  • 10. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 10/74 Prune ­ YOLO $ docker run -d --restart=unless-stopped --name cleanup -v /var/run/docker.sock:/var/run/docker.sock docker /bin/sh -c "while true; do docker system prune -f; sleep 1h; done" $ docker service create --mode global --name cleanup --mount type=bind,src=/var/run/docker.sock, dst=/var/run/docker.sock docker /bin/sh -c "while true; do docker system prune -f; sleep 1h; done" Tips and Tricks of the Docker Captains - @sudo_bmitch10 / 74
  • 11. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 11/74 Container Logs Tips and Tricks of the Docker Captains - @sudo_bmitch11 / 74
  • 12. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 12/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 12 / 74
  • 13. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 13/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 13 / 74
  • 14. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 14/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 14 / 74
  • 15. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 15/74 Clean Your Logs $ cat docker-compose.yml version: '3.7' services: app: image: sudobmitch/loggen command: [ "150", "180" ] logging: options: max-size: "10m" max-file: "3" Tips and Tricks of the Docker Captains - @sudo_bmitch15 / 74
  • 16. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 16/74 Clean Your Logs version: '3.7' x-defaults: service: &default-svc image: sudobmitch/loggen logging: { options: { max-size: "10m", max-file: "3" } } services: cat: <<: *default-svc command: [ "300", "120" ] environment: { pet: "cat" } turtle: <<: *default-svc labels: { name: "gordon", levels: "all the way down" } Tips and Tricks of the Docker Captains - @sudo_bmitch16 / 74
  • 17. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 17/74 Clean Your Logs Best option to prevent container logs from filling disk space $ cat /etc/docker/daemon.json { "log-driver": "local", "log-opts": {"max-size": "10m", "max-file": "3"} } $ systemctl reload docker Tips and Tricks of the Docker Captains - @sudo_bmitch17 / 74
  • 18. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 18/74 Tips and Tricks of the Docker Captains - @sudo_bmitch18 / 74
  • 19. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 19/74 Tips and Tricks of the Docker Captains - @sudo_bmitch19 / 74
  • 20. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 20/74 Networking Tips and Tricks of the Docker Captains - @sudo_bmitch20 / 74
  • 21. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 21/74 Subnet Collisions Docker networks sometimes conflict with other networks Tips and Tricks of the Docker Captains - @sudo_bmitch21 / 74
  • 22. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 22/74 Subnet Collisions Docker networks sometimes conflict with other networks BIP, bridge network named "bridge" $ cat /etc/docker/daemon.json { "bip": "10.15.0.1/24" } Tips and Tricks of the Docker Captains - @sudo_bmitch22 / 74
  • 23. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 23/74 Subnet Collisions Default address poll added in 18.06 $ cat /etc/docker/daemon.json { "bip": "10.15.0.1/24", "default-address-pools": [ {"base": "10.20.0.0/16", "size": 24}, {"base": "10.40.0.0/16", "size": 24} ] } Tips and Tricks of the Docker Captains - @sudo_bmitch23 / 74
  • 24. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 24/74 Subnet Collisions $ docker swarm init --help ... --default-addr-pool ipNetSlice --default-addr-pool-mask-length uint32 Tips and Tricks of the Docker Captains - @sudo_bmitch24 / 74
  • 25. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 25/74 Subnet Collisions $ docker swarm init --help ... --default-addr-pool ipNetSlice --default-addr-pool-mask-length uint32 $ docker swarm init --default-addr-pool 10.20.0.0/16 --default-addr-pool 10.40.0.0/16 --default-addr-pool-mask-length 24 Tips and Tricks of the Docker Captains - @sudo_bmitch25 / 74
  • 26. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 26/74 Network Debugging Debugging networks from the host doesn't see inside the container namespace Debugging inside the container means installing tools inside that container Tips and Tricks of the Docker Captains - @sudo_bmitch26 / 74
  • 27. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 27/74 Network Debugging Debugging networks from the host doesn't see inside the container namespace Debugging inside the container means installing tools inside that container Sidecars aren't just for Kubernetes Tips and Tricks of the Docker Captains - @sudo_bmitch27 / 74
  • 28. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 28/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 28 / 74
  • 29. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 29/74 Network Debugging $ docker run --name web -p 9999:80 -d nginx $ docker run -it --rm --net container:web nicolaka/netshoot ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:* Tips and Tricks of the Docker Captains - @sudo_bmitch29 / 74
  • 30. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 30/74 Layered Filesystem Tips and Tricks of the Docker Captains - @sudo_bmitch30 / 74
  • 31. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 31/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 31 / 74
  • 32. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 32/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 32 / 74
  • 33. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 33/74 Understanding Layers $ docker image build --rm=false --no-cache . $ docker container diff ... Tips and Tricks of the Docker Captains - @sudo_bmitch33 / 74
  • 34. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 34/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 34 / 74
  • 35. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 35/74 Understanding Layers Delete temporary file in the same step where they are created Small changes to big files are big changes Merge your RUN commands together Tips and Tricks of the Docker Captains - @sudo_bmitch35 / 74
  • 36. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 36/74 From Bad ... FROM golang:1.11 RUN adduser --disabled-password --gecos appuser appuser WORKDIR /src COPY . /src/ RUN go build -o app . WORKDIR / RUN cp /src/app /app RUN chown appuser /app RUN chmod 755 /app RUN rm -r /src USER appuser CMD /app Tips and Tricks of the Docker Captains - @sudo_bmitch36 / 74
  • 37. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 37/74 ... to Okay FROM golang:1.11 RUN adduser --disabled-password --gecos appuser appuser COPY . /src/ RUN cd /src && go build -o app . && cd / && cp /src/app /app && chown appuser /app && chmod 755 /app && rm -r /go/pkg /root/.cache/go-build /src USER appuser CMD /app Tips and Tricks of the Docker Captains - @sudo_bmitch37 / 74
  • 38. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 38/74 Multi­stage Builds Everything we learned about making efficient images is now wrong Build stage splits RUN lines to maximize caching Only the released stage needs to be layer efficient Tips and Tricks of the Docker Captains - @sudo_bmitch38 / 74
  • 39. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 39/74 FROM golang:1.11-alpine as build RUN apk add --no-cache git ca-certificates RUN adduser -D appuser WORKDIR /src COPY . /src/ RUN CGO_ENABLED=0 go build -o app . FROM scratch as release COPY --from=build /etc/passwd /etc/group /etc/ COPY --from=build /src/app /app USER appuser CMD [ "/app" ] FROM alpine as dev COPY --from=build /src/app /app CMD [ "/app" ] FROM release Tips and Tricks of the Docker Captains - @sudo_bmitch39 / 74
  • 40. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 40/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 40 / 74
  • 41. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 41/74 "Hold my beer.""Hold my beer." ­­BuildKit­­BuildKit Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch41 / 7441 / 74
  • 42. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 42/74 BuildKit Features For Everyone GA in Docker 18.09 Context only pulls needed files Multi-stage builds use a dependency graph Cache from a remote registry Pruning has options for cache age and size to keep Tips and Tricks of the Docker Captains - @sudo_bmitch42 / 74
  • 43. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 43/74 BuildKit Cache Pruning $ docker builder prune --keep-storage=1GB --filter until=72h Tips and Tricks of the Docker Captains - @sudo_bmitch43 / 74
  • 44. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 44/74 BuildKit Cache Pruning $ docker builder prune --keep-storage=1GB --filter until=72h $ cat /etc/docker/daemon.json { "builder": { "gc": { "enabled": true, "policy": [ {"keepStorage": "512MB", "filter": ["unused-for=168h"]]}, {"keepStorage": "30GB", "all": true} ] } } } Tips and Tricks of the Docker Captains - @sudo_bmitch44 / 74
  • 45. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 45/74 BuildKit Experimental Features Frontend parser can be changed Bind Mounts, from build context or another image Cache Mounts, similar to a named volume Tmpfs Mounts Build Secrets, file never written to image filesystem SSH Agent, private Git repos Tips and Tricks of the Docker Captains - @sudo_bmitch45 / 74
  • 46. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 46/74 # syntax=docker/dockerfile:experimental FROM golang:1.11-alpine as build RUN apk add --no-cache git ca-certificates tzdata RUN adduser -D appuser WORKDIR /src COPY . /src/ RUN --mount=type=cache,id=gomod,target=/go/pkg/mod/cache --mount=type=cache,id=goroot,target=/root/.cache/go-build CGO_ENABLED=0 go build -o app . USER appuser CMD ./app Tips and Tricks of the Docker Captains - @sudo_bmitch46 / 74
  • 47. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 47/74 Tips and Tricks of the Docker Captains - @sudo_bmitch 00:00 47 / 74
  • 48. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 48/74 Enable BuildKit $ export DOCKER_BUILDKIT=1 $ docker build -t your_image . Tips and Tricks of the Docker Captains - @sudo_bmitch48 / 74
  • 49. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 49/74 Enable BuildKit $ export DOCKER_BUILDKIT=1 $ docker build -t your_image . $ cat /etc/docker/daemon.json { "features": {"buildkit": true} } Tips and Tricks of the Docker Captains - @sudo_bmitch49 / 74
  • 50. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 50/74 Volumes Tips and Tricks of the Docker Captains - @sudo_bmitch50 / 74
  • 51. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 51/74 Local Volume Driver Tips and Tricks of the Docker Captains - @sudo_bmitch51 / 74
  • 52. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 52/74 NFS Mounts $ docker volume create --driver local --opt type=nfs --opt o=nfsvers=4,addr=nfs.example.com,rw --opt device=:/path/on/server foo Tips and Tricks of the Docker Captains - @sudo_bmitch52 / 74
  • 53. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 53/74 NFS Mounts version: '3.7' volumes: nfs-data: driver: local driver_opts: type: nfs o: nfsvers=4,addr=nfs.example.com,rw device: ":/path/to/dir" services: app: volumes: - nfs-data:/data ... Tips and Tricks of the Docker Captains - @sudo_bmitch53 / 74
  • 54. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 54/74 Other Filesystem Mounts version: '3.7' volumes: ext-data: driver: local driver_opts: type: ext4 o: ro device: "/dev/sdb1" services: app: volumes: - ext-data:/data ... Tips and Tricks of the Docker Captains - @sudo_bmitch54 / 74
  • 55. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 55/74 Overlay Filesystem as a Volume version: '3.7' volumes: overlay-data: driver: local driver_opts: type: overlay device: overlay o: lowerdir=${PWD}/data2:${PWD}/data1, upperdir=${PWD}/upper,workdir=${PWD}/workdir services: app: volumes: - overlay-data:/data ... Tips and Tricks of the Docker Captains - @sudo_bmitch55 / 74
  • 56. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 56/74 Named Bind Mount version: '3.7' volumes: bind-vol: driver: local driver_opts: type: none o: bind device: /home/user/host-dir services: app: volumes: - "bind-vol:/container-dir" - "./code:/code" ... Tips and Tricks of the Docker Captains - @sudo_bmitch56 / 74
  • 57. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 57/74 That's nice, but I just use:That's nice, but I just use: $(pwd)/code:/code$(pwd)/code:/code Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch57 / 7457 / 74
  • 58. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 58/74 That's nice, but I just use:That's nice, but I just use: $(pwd)/code:/code$(pwd)/code:/code "$(pwd)/code:/code""$(pwd)/code:/code" Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch58 / 7458 / 74
  • 59. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 59/74 Dockerfile for Java FROM openjdk:jdk as build RUN apt-get update && apt-get install -y maven && useradd -m app COPY code /code RUN mvn build CMD ["java", "-jar", "/code/app.jar"] USER app FROM openjdk:jre as release RUN useradd -m app COPY --from=build /code/app.jar /app.jar CMD ["java", "-jar", "/app.jar"] USER app Tips and Tricks of the Docker Captains - @sudo_bmitch59 / 74
  • 60. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 60/74 Developer Compose File version: '3.7' volumes: m2: services: app: build: context: . target: build image: registry:5000/app/app:dev command: "/bin/sh -c 'mvn build && java -jar /code/app.jar'" volumes: - m2:/home/app/.m2 - ./code:/code Tips and Tricks of the Docker Captains - @sudo_bmitch60 / 74
  • 61. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 61/74 Problem with the Developer Workflow Error accessing /code: permission denied Tips and Tricks of the Docker Captains - @sudo_bmitch61 / 74
  • 62. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 62/74 Problem with the Developer Workflow Error accessing /code: permission denied UID for app inside the container doesn't match our UID on the host Tips and Tricks of the Docker Captains - @sudo_bmitch62 / 74
  • 63. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 63/74 Problem with the Developer Workflow Error accessing /code: permission denied UID for app inside the container doesn't match our UID on the host Unless you're on MacOS or VirtualBox Tips and Tricks of the Docker Captains - @sudo_bmitch63 / 74
  • 64. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 64/74 Fixing UID/GID Possible solutions: Run everything as root Change permissions to 777 Adjust each developers uid/gid to match image Adjust image uid/gid to match developers Change the container uid/gid from run or compose Tips and Tricks of the Docker Captains - @sudo_bmitch64 / 74
  • 65. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 65/74 Fixing UID/GID Possible bad solutions: Run everything as root Change permissions to 777 Adjust each developers uid/gid to match image Adjust image uid/gid to match developers Change the container uid/gid from run or compose Tips and Tricks of the Docker Captains - @sudo_bmitch65 / 74
  • 66. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 66/74 Fixing UID/GID Possible bad solutions: Run everything as root Change permissions to 777 Adjust each developers uid/gid to match image Adjust image uid/gid to match developers Change the container uid/gid from run or compose Another solution: "Use a shell script" - Some Ops Guy Tips and Tricks of the Docker Captains - @sudo_bmitch66 / 74
  • 67. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 67/74 DisclaimerDisclaimer The following slide may not be suitable for all audiencesThe following slide may not be suitable for all audiences Tips and Tricks of the Docker Captains - @sudo_bmitchTips and Tricks of the Docker Captains - @sudo_bmitch67 / 7467 / 74
  • 68. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 68/74 Fixing UID/GID: fix­perms # update the uid if [ -n "$opt_u" ]; then OLD_UID=$(getent passwd "${opt_u}" | cut -f3 -d:) NEW_UID=$(stat -c "%u" "$1") if [ "$OLD_UID" != "$NEW_UID" ]; then echo "Changing UID of $opt_u from $OLD_UID to $NEW_UID" usermod -u "$NEW_UID" -o "$opt_u" if [ -n "$opt_r" ]; then find / -xdev -user "$OLD_UID" -exec chown -h "$opt_u" {} ; fi fi fi Tips and Tricks of the Docker Captains - @sudo_bmitch68 / 74
  • 69. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 69/74 Fixing UID/GID: Dockerfile FROM openjdk:jdk as build COPY --from=sudobmitch/base:scratch / / RUN apt-get update && apt-get install -y maven && useradd -m app COPY code /code RUN mvn build COPY entrypoint.sh /usr/bin/ ENTRYPOINT ["/usr/bin/entrypoint.sh"] CMD ["java", "-jar", "/code/app.jar"] USER app Tips and Tricks of the Docker Captains - @sudo_bmitch69 / 74
  • 70. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 70/74 Fixing UID/GID: entrypoint.sh #!/bin/sh if [ "$(id -u)" = "0" ]; then # running on a developer laptop as root fix-perms -r -u app -g app /code exec gosu app "$@" else # running in production as a user exec "$@" fi Tips and Tricks of the Docker Captains - @sudo_bmitch70 / 74
  • 71. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 71/74 Fixing UID/GID: Developer Compose File version: '3.7' volumes: m2: services: app: build: context: . target: build image: registry:5000/app/app:dev command: "/bin/sh -c 'mvn build && java -jar /code/app.jar'" user: "0:0" volumes: - m2:/home/app/.m2 - ./code:/code Tips and Tricks of the Docker Captains - @sudo_bmitch71 / 74
  • 72. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 72/74 Fixing UID/GID: Production Compose File version: '3.7' services: app: image: registry:5000/app/app:${build_num} Tips and Tricks of the Docker Captains - @sudo_bmitch72 / 74
  • 73. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 73/74 Fixing UID/GID: Recap Developers: Mount code as from the host Container starts entrypoint as root Entrypoint changes uid of app user to match uid of /code Entrypoint switches from root to app Pid 1 is the app with a uid matching the host Reads and writes to /code happen as the developers uid Production: Runs without root or a volume Entrypoint skips fix-perms and gosu Tips and Tricks of the Docker Captains - @sudo_bmitch73 / 74
  • 74. 5/6/2019 Tips and Tricks From A Docker Captain - Brandon Mitchell https://sudo-bmitch.github.io/presentations/dc2019/tips-and-tricks-of-the-captains.html#28 74/74 Brandon Mitchell Twitter: @sudo_bmitch GitHub: sudo-bmitch Thank You Rate this session in the DockerCon App github.com/sudo-bmitch/presentations github.com/sudo-bmitch/docker-base 74 / 74