19
DOCKER FOR DEVELOPERS BY PETE FREITAG

DOCKER FOR DEVELOPERS - petefreitag.com

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DOCKER FOR DEVELOPERS - petefreitag.com

DOCKER FOR DEVELOPERS

BY PETE FREITAG

Page 2: DOCKER FOR DEVELOPERS - petefreitag.com

WHAT IS DOCKER?

CONTAINERS?

photo (cc) jumilla/14403331148 on flickr

Page 3: DOCKER FOR DEVELOPERS - petefreitag.com

CONTAINERSLETS START WITH

Page 4: DOCKER FOR DEVELOPERS - petefreitag.com

WHAT IS A CONTAINER

• A packaged program or service

• Similar to a VM a container can include an OS.

• Virtualization abstracts the hardware

• Containers abstract the OS kernel

• Containers are lighter than VMs

• A container is a running instance of an image.

Page 5: DOCKER FOR DEVELOPERS - petefreitag.com

LAYERSIMAGES HAVE

photo (cc) flickr tenaciousme/5799408683

And this is good

Page 6: DOCKER FOR DEVELOPERS - petefreitag.com

IMAGE LAYERS

• Images are created by inheriting from a BASE image

• This docker to cache similar layers

• Saves file system space between similar containers

• Also saves downloading

Page 7: DOCKER FOR DEVELOPERS - petefreitag.com

LETS START A CONTAINER

• First download and install docker

• Open Terminal or Command Prompt

• Execute docker run:

• docker run imageName

Page 8: DOCKER FOR DEVELOPERS - petefreitag.com

RUN SQL SERVER

docker run microsoft/mssql-server-linux:latest

Page 9: DOCKER FOR DEVELOPERS - petefreitag.com

WHERE DO YOU FIND IMAGES?

Page 10: DOCKER FOR DEVELOPERS - petefreitag.com

COMMAND ARGS

DOCKER RUN

• -p local:container map a local port to the container port

• eg -p 8084:80 maps local port 8084 to port 80 on the container.

• -e 'VAR_NAME=value' set an environment variable

• More options: https://docs.docker.com/engine/reference/run/

Page 11: DOCKER FOR DEVELOPERS - petefreitag.com

RUN SQL SERVER

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=sqlserver123' -p 8433:1433 -d microsoft/mssql-server-linux:latest

Page 12: DOCKER FOR DEVELOPERS - petefreitag.com

OPEN A SHELL

HOW TO GET INSIDE A CONTAINER

docker exec -it container-id /bin/bash

docker ps

how do you know the container-id?

Page 13: DOCKER FOR DEVELOPERS - petefreitag.com

EASIER WAYS TO RUN CONTAINERS

HAVE I LOST YOU? DON'T WORRY THERE ARE

Page 14: DOCKER FOR DEVELOPERS - petefreitag.com

KITEMATIC GUI

EASIER WAYS TO START CONTAINERS

Page 15: DOCKER FOR DEVELOPERS - petefreitag.com

ITS NOT TOO HARD

MAKING YOUR OWN IMAGES

1. Create a Dockerfile

A. Use FROM to specify what image your image will inherit from, some examples (eg: FROM centos:7 )

B. Use RUN to execute commands

C. Use COPY to put files into the image

D. Use EXPOSE to expose a network port.

E. Use CMD to tell it what executable to run.

Page 16: DOCKER FOR DEVELOPERS - petefreitag.com

DOCKER COMPOSE

ANOTHER WAY TO RUN CONTAINERS

• Create a docker-compose.yml file

• This allows you to define all the containers used by a project.

• You can also define relationships between the containers.

• Start all the containers by running: docker-compose up

• This file is all that is needed to replicate the infrastructure on any number of developer machines or servers.

Page 17: DOCKER FOR DEVELOPERS - petefreitag.com

DOCKER COMPOSE

EXAMPLES

Page 18: DOCKER FOR DEVELOPERS - petefreitag.com

THINGS TO KEEP IN MIND

• A container typically consists of a single process.

• The process should log output to standard output.

Page 19: DOCKER FOR DEVELOPERS - petefreitag.com

WRAPPING IT UP

CONCLUSIONS

• Docker is a fast paced technology with lots of bells and whistles, we have hardly scratched the surface.

• Docker in production could be the topic of many further presentations. Lots of deployment options with even more bells and whistles.