1 of 45

WORKSHOP

Rafael Dutra

2 of 45

WHO AM I?

  • Rafael Dutra
  • SysAdmin and DevOps Enthusiast
  • Security Information - UNISINOS 2008 - ?
  • Linux user since 2005
  • Docker user since 2015
  • PHP (Laravel)/Shell/Ruby

3 of 45

WORKING WITH/AT

Vagrant, Puppet, Terraform, Continuous Integration, Continuous Deployment, Shell Scripting, Docker, AWS (learning) ...

Shared Services Ops Team

@crossover - https://crossover.com

@jivesoftware - https://jivesoftware.com

@aurea - https://www.aurea.com

4 of 45

AGENDA

  • What’s Docker?
  • Container vs Virtual Machine
  • Why should I use Docker?
  • Terminology
  • Images and Layers
  • Containers and Layers
  • Dockerfile anatomy

5 of 45

WHAT'S DOCKER?

  • Open Source technology
  • Agility, accelerate software development and deployment
  • Portability, eliminate the "works on my machine"
  • Container is not Virtual Machine

6 of 45

CONTAINER VS VIRTUAL MACHINES

7 of 45

WHY SHOULD I USE DOCKER?

  • Infrastructure as Code - IAC
  • All application is an image
  • Works on my machine, no more!
  • Set up locally the same environment that you have in production, or any other environment
  • Tests, a lot of them
  • Community

8 of 45

TERMINOLOGY

  • Images = is our “how it was built” / what we want to run
  • Containers = runs images in a dynamic way. By dynamic I meant: multiple containers can run the same image doing different things.
  • Volumes = where we want to store our data, could be our physical directory or a docker volume

9 of 45

IMAGES AND LAYERS

10 of 45

CONTAINERS AND LAYERS

11 of 45

DOCKERFILE

# base image

FROM nginx

# copy a file to a specific directory

COPY index.html /usr/share/nginx/html

# running the application

CMD ["nginx", "-g", "daemon off;"]

12 of 45

HANDS ON

13 of 45

HANDS ON AGENDA

  • Docker installation
  • The basics, running containers
  • Interacting with containers
  • Dockerfile
  • Using volumes
  • Docker Compose

14 of 45

DOCKER INSTALLATION

curl -fsSL https://get.docker.com -o get-docker.sh

sudo sh get-docker.sh

15 of 45

DOCKER BASICS

Full commands

docker

16 of 45

DOCKER BASICS

Need a medic? ask for help

docker <command> --help

17 of 45

DOCKER BASICS

Running our first container

docker run alpine hostname

18 of 45

DOCKER BASICS

Running our second container

docker run hello-world

19 of 45

DOCKER BASICS

Everything comes from an image

docker run alpine hostname

20 of 45

DOCKER BASICS

To list all images

docker image ls

21 of 45

DOCKER BASICS

To search an image

docker search alpine

22 of 45

DOCKER BASICS

To pull (download) an image

docker image pull ubuntu

23 of 45

DOCKER BASICS

To pull (download) an specific image version

docker image pull ubuntu:17.10

24 of 45

DOCKER BASICS

Running our first web container

docker run --detach --publish 45000:80 nginx

  • action that we want to do
  • options to detach (run it in background) and publish ports
  • port that we want to access in our machine
  • port running in the container
  • image we are using at this moment

25 of 45

MANIPULATE CONTAINERS

To list running containers

docker container ls

26 of 45

MANIPULATE CONTAINERS

To list all containers

docker container ls -a

27 of 45

MANIPULATE CONTAINERS

Stopping a container

docker container stop <id>

28 of 45

MANIPULATE CONTAINERS

Starting a container

docker container start <id>

29 of 45

MANIPULATE CONTAINERS

Interacting with them

docker run --interactive --tty ubuntu /bin/bash

30 of 45

MANIPULATE CONTAINERS

Executing …. something without enter in a container

docker exec <id> <command>

31 of 45

MANIPULATE CONTAINERS

Attaching.�important: Containers needs some “bash/sh” running

docker attach <id>

32 of 45

MANIPULATE IMAGES

To remove an image

Important: Only containers removed

docker image rm alpine

33 of 45

CREATING IMAGES (Dockerfile)

FROM php:7.2.5-cli-alpine3.7

CMD ["php", "--version"]

34 of 45

CREATING IMAGES

docker build --tag fossday/php:7.2 .

35 of 45

RUN FORREST … RUN

docker run --rm fossday/php:7.2

36 of 45

RUN FORREST … RUN

docker run --rm fossday/php:7.2 --help

37 of 45

RUN FORREST … RUN WITH MATH

<?php

$val1 = 60;

$val2 = 20;

echo "Soma de ${val1} + ${val2} igual a: " . ($val1 + $val2) . "\n";

Lets create a file called: soma.php

38 of 45

RUN FORREST … RUN

docker run --rm \

-v $(pwd)/soma.php:/root/soma.php \

fossday/php:7.2 \

php -f /root/soma.php

39 of 45

CLEANING

Remove all containers that are in stopped state (dangling)

docker container prune

40 of 45

DOCKER COMPOSE

  • Orchestrate containers
  • YAML
  • Single file: docker-compose.yaml
  • Multi containers

41 of 45

DOCKER COMPOSE INSTALLATION

https://goo.gl/8mbW87

42 of 45

DOCKER COMPOSE

docker-compose up -d

43 of 45

HERE WE GO

QUESTIONS ?

44 of 45

GET IN TOUCH

45 of 45

SEE YOU LATER

THANK YOU