docker irl - muffin man - docker-irl.pdf · • docker compose • swarm mode • venice. thank...

24

Upload: others

Post on 22-May-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44
Page 2: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Get familiar with Docker key concepts and basic usage.

Miloš Pavlićević Developer at Work & Co [email protected]

DOCKER IRL

Page 3: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

OVERVIEW• What is Docker? • Docker architecture• Why Docker?• Usage & workflow• Examples• Best practices• More!

Page 4: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

WHAT IS DOCKER?Docker engine

• Docker Daemon (in charge of building images and running/managing containers)

• Docker CLI (interfaces Docker API)

• Docker Registry

“It works on my machine!”

Architecture

• Client - Server (CLI - Daemon)

• Docker HUB (cloud service, library, storage, automation)

Page 5: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

• Containers Not VMs. The concept of resource allocation/isolation is present, however in a more efficient and less robust manner. (OS virtualization vs HW virtualization)

• Images A snapshot of container.

• Container lifecycle Create, start, pause, unpause, stop, kill, destroy.

• Layers and container states Each change to a container is treated as a separate layer. Each container layer can be converted into an image. Git-like approach.

DOCKER ARCHITECTURE

Page 6: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44
Page 7: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

WHY DOCKER? • Platform independence

• Lightweight, portable

• Simplicity - easy to install, operate

and automate processes.

• Awesome for micro-services

• Huge community

• It’s free!

“3000+ Community contributors!”

Page 8: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

• Commands

• Automation Automate container control via scripts, webhooks, etc.

USAGE & WORKFLOW

docker ps [opts] # lists containers docker run [opts] <image_name> # creates container based on image docker attach <container_name> # attach to container’s process docker exec [opts] <container_name> # execute a command within container

# docker stop/start/pause/unpause/kill …

docker rm <container_name/id> # removes specified (non-running) container docker rmi <image_name/id> # removes specified (currently unused) image

docker commit [opts] <container> [<repo>[:tag]] # create an image docker build [opts] # create an image, based on Dockerfile

# docker login/push/pull …

Page 9: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Time for example!

Page 10: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

• Dockerfiles

• Port mapping

• Volumes

• Debugging

• Docker Compose

USAGE & WORKFLOW

FROM httpd

MAINTAINER Milos Pavlicevic <[email protected]> #deprecated, use LABEL

COPY ./app/build/ /usr/local/apache2/htdocs/

CMD ["httpd-foreground"]

Page 11: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

More examples

Page 12: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Best practices:

Page 13: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Containers should be disposable and have a single responsibility.

Page 14: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Keep your stuff lean, by minimizing dependencies, layers, and don’t forget

about .dockerignore.

Page 15: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

# Bad COPY file.tar.gz tmp/ # new layer RUN tar -xvf file.tar.gz # new layer RUN rm file.tar.gz # new layer

RUN apt-get install -y package-one # new layer RUN apt-get install -y package-two # new layer RUN apt-get install -y package-three # new layer

# ===================================================== # Good COPY file.tar.gz tmp/ # new layer RUN tar -xvf file.tar.gz \ && rm file.tar.gz \ && apt-get install \ package-one \ package-two \ package-three # new layer

Page 16: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

But also make your Dockerfiles readable.

Page 17: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

# Use LABEL LABEL "com.example.vendor"="ACME Incorporated" LABEL com.example.label-with-value="foo" LABEL version="1.0" LABEL description="This text illustrates \ that label-values can span multiple lines."

# Sort arguments alphanumerically RUN apt-get install -y \ a-package \ b-package \ m-package \ z-package

# Use EXPOSE EXPOSE 27017

Page 18: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Make the most out of caching mechanism…

…but also beware of it.

Page 19: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

# Bad RUN apt-get update RUN apt-get install -y my-package

# Good RUN apt-get update && apt-get install -y \ My-package-2

#====================================================== # Bad RUN git clone <git_repository> RUN npm install

# Good ADD https://api.github.com/repos/<user>/<repo>/git/refs/heads/<branch> version.json RUN git clone -b <branch> <git_repository>

Page 20: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Take care of logs.

Page 21: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Stay secure.

Page 22: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

More:

• Docker Compose• Swarm mode• Venice

Page 23: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

Thank you! Questions?

[email protected]

Page 24: DOCKER IRL - Muffin Man - Docker-IRL.pdf · • Docker Compose • Swarm mode • Venice. Thank you! Questions? pavlicevic@work.co. . Title: Docker-IRL Created Date: 5/17/2017 8:42:44

www.work.co