Slide 1

Slide 1 text

Docker Gilson Filho

Slide 2

Slide 2 text

Alert!

Slide 3

Slide 3 text

Slides with this ↑ show updates about Docker and your ecosystem

Slide 4

Slide 4 text

What is

Slide 5

Slide 5 text

Docker Begins

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

What is Docker ? “ Docker is an open platform for building, shipping and running distributed applications. docker.io

Slide 11

Slide 11 text

What is Docker ?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

An open framework to assemble specialized container systems without reinventing the wheel. Moby

Slide 15

Slide 15 text

Going forward, Docker will be assembled using Moby, see for more details. Moby and Docker Moby

Slide 16

Slide 16 text

What is Docker Moby ?

Slide 17

Slide 17 text

Back to THE 90's

Slide 18

Slide 18 text

MY APP + A REAL Server =

Slide 19

Slide 19 text

VIRTUAL MACHINEs

Slide 20

Slide 20 text

VIRTUAL MACHINEs

Slide 21

Slide 21 text

VIRTUAL MACHINEs

Slide 22

Slide 22 text

Docker containers

Slide 23

Slide 23 text

Docker containers

Slide 24

Slide 24 text

Docker containers VM Docker

Slide 25

Slide 25 text

LXC = OS-level virtualization for running multiple isolated Linux systems "LINUX CONTAINERS"

Slide 26

Slide 26 text

cgroups = Linux kernel feature that limits and isolates the resource usage (CPU, disk I/O, network, etc.) "CONTROL GROUPS"

Slide 27

Slide 27 text

AUFs = Filesystem which is based on images where every modification is a diff from the previous one (Like commits in git) "Adv. multi layered Unification FS"

Slide 28

Slide 28 text

Docker > 1.11 Engine is now built on runC and containerd

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

How to Install

Slide 31

Slide 31 text

HOW TO INSTALL ? http://docs.docker.com/installation

Slide 32

Slide 32 text

HOW TO INSTALL ? http://docs.docker.com/installation

Slide 33

Slide 33 text

Linux Debian https://docs.docker.com/engine/installation/linux/debian/ Fedora https://docs.docker.com/engine/installation/linux/fedora/ Ubuntu https://docs.docker.com/engine/installation/linux/ubuntu/

Slide 34

Slide 34 text

Windows e OS X https://www.docker.com/products/docker-toolbox​

Slide 35

Slide 35 text

Windows

Slide 36

Slide 36 text

OS X

Slide 37

Slide 37 text

Docker HUB

Slide 38

Slide 38 text

Over 1.2B Pulls from Docker Hub 5.6M 65 240K Pulls per Day Pulls per Second Repositories on Docker Hub

Slide 39

Slide 39 text

Docker Store next generation of Docker Hub

Slide 40

Slide 40 text

Docker Store next generation of Docker Hub https://docs.docker.com/docker-store https://store.docker.com

Slide 41

Slide 41 text

Dictionary

Slide 42

Slide 42 text

Image An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files.

Slide 43

Slide 43 text

Container A container is a runtime instance of an image – what the image becomes in memory when actually executed. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so.

Slide 44

Slide 44 text

Docker Commands

Slide 45

Slide 45 text

Docker Search ~ $ docker search -h Usage: docker search [OPTIONS] TERM Search the Docker Hub for images --automated=false Only show automated builds --no-trunc=false Don't truncate output -s, --stars=0 Only displays with at least x stars

Slide 46

Slide 46 text

Docker Search arch hello-world DESCRIPTION STARS OFFICIAL AU Hello World! (an example of minimal Docker... 24 [OK] orld Image to test docker deployments. Has Apac... 12 [O et-hello-world ASP.NET vNext - Hello World 1 [O ocker-hello-world 1 [O i/devops-hello-world-app Example application for deploying using Co... 1 [O -world 0 [O o-world Hello World web server in under 2.5 MB 0 [O llo-world this is 3rd POC 0 [O lo-world 0 [O llo-world 0 [O -hello-world Java Hello World Test Docker Image 0 [O world 0 [O ello-world A docker auto build test application 0 [O lr-hello-world A simple Hello World sample, running as a ... 0 [O /docker-hello-world 0 [O -world 0 [O ocker-java-hello-world This is an automated build of docker java-... 0 [O r-hello-world Hello world automated build 0 [O hello-world-node-docker A simple hello world app 0 [O

Slide 47

Slide 47 text

Docker pull $ docker pull -h age: docker pull [OPTIONS] NAME[:TAG] | [REGISTRY_HOST[:REGISTRY_PORT]/]NAME[:TAG] ll an image or a repository from the registry -a, --all-tags=false Download all tagged images in the repository --disable-content-trust=true Skip image verification

Slide 48

Slide 48 text

Docker pull ~ $ docker pull hello-world latest: Pulling from hello-world 535020c3e8ad: Pull complete af340544ed62: Pull complete Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c Status: Downloaded newer image for hello-world:latest ~ $

Slide 49

Slide 49 text

RUN Command ~ $ docker run -h Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container -a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO weight (relative weight) -c, --cpu-shares=0 CPU shares (relative weight) [...]

Slide 50

Slide 50 text

RUN Command ~ $ docker run ubuntu:latest echo "Docker is awesome" Unable to find images 'ubuntu:latest' locally latest: Pulling from ubuntu d3a1f33e8a5a: Pull complete c22013c84729: Pull complete d74508fb6632: Pull complete 91e54dfb1179: Pull complete ubuntu:latest: The image you are pulling has been verified. Digest: sha256:73fbe2308f5f5cb6e343425831b8ab44f10bbd77070ecdfbe4081daa4dbe3ed1 Status: Downloaded newer image for ubuntu:latest Docker is awesome ~ $

Slide 51

Slide 51 text

ocker run -it ubuntu:latest /bin/bash b91b6d0cf193:/# ls boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var b91b6d0cf193:/# exit RUN Command ~ $ docker run ubuntu:latest echo "Docker is awesome" Unable to find images 'ubuntu:latest' locally latest: Pulling from ubuntu d3a1f33e8a5a: Pull complete c22013c84729: Pull complete d74508fb6632: Pull complete 91e54dfb1179: Pull complete ubuntu:latest: The image you are pulling has been verified. Digest: sha256:73fbe2308f5f5cb6e343425831b8ab44f10bbd77070ecdfbe4081daa4dbe3ed1 Status: Downloaded newer image for ubuntu:latest Docker is awesome ~ $

Slide 52

Slide 52 text

images & rmi command ~ $ docker images -h Usage: docker images [OPTIONS] [REPOSITORY] List images -a, --all=false Show all images (default hides intermediate images) --digests=false Show digests -f, --filter=[] Filter output based on conditions provided --help=false Print usage --no-trunc=false Don't truncate output -q, --quiet=false Only show numeric IDs

Slide 53

Slide 53 text

images & rmi command r images Y TAG IMAGE ID CREATED VIRTUAL latest 91e54dfb1179 16 minutes ago 188.4 MB ld latest af340544ed62 4 minutes ago 960 B

Slide 54

Slide 54 text

images & rmi command er images RY TAG IMAGE ID CREATED VIRTUAL latest 91e54dfb1179 16 minutes ago 188.4 M rld latest af340544ed62 4 minutes ago 960 B er rmi -f hello-world : hello-world:latest af340544ed62de0680f441c71fa1a80cb084678fed42bae393e543faea3a572c 535020c3e8add9d6bb06e5ac15a261e73d9b213d62fb2c14d752b8e189b2b912 er images RY TAG IMAGE ID CREATED VIRTUAL latest 91e54dfb1179 16 minutes ago 188.4 M

Slide 55

Slide 55 text

PS & RM command ~ $ docker ps -h Usage: docker ps [OPTIONS] List containers -a, --all=false Show all containers (default shows just running) --before="" Show only container created before Id or Name -f, --filter=[] Filter output based on conditions provided -l, --latest=false Show the latest created container, include non-running -n=-1 Show n last created containers, include non-running --no-trunc=false Don't truncate output -q, --quiet=false Only display numeric IDs -s, --size=false Display total file sizes --since="" Show created since Id or Name, include non-running --format=[] Pretty-print containers using a Go template

Slide 56

Slide 56 text

PS & RM command IMAGE COMMAND CREATED STATUS PORTS N postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp p ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds a ubuntu:latest "/bin/bash" About a minute ago Up About a minute i

Slide 57

Slide 57 text

PS & RM command -f 89951e446cf0 IMAGE COMMAND CREATED STATUS PORTS N ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds a ubuntu:latest "/bin/bash" About a minute ago Up About a minute i s IMAGE COMMAND CREATED STATUS PORTS postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds ubuntu:latest "/bin/bash" About a minute ago Up About a minute

Slide 58

Slide 58 text

exec command ~ $ docker exec -h Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container -d, --detach=false Detached mode: run command in the background -i, --interactive=false Keep STDIN open even if not attached -t, --tty=false Allocate a pseudo-TTY -u, --user= Username or UID (format: [:])

Slide 59

Slide 59 text

exec command IMAGE COMMAND CREATED STATUS PORTS N postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp p ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds a ubuntu:latest "/bin/bash" About a minute ago Up About a minute i

Slide 60

Slide 60 text

exec command IMAGE COMMAND CREATED STATUS PORTS NA postgres:latest "/docker-entrypoint. 8 seconds ago Up 7 seconds 5432/tcp pe ubuntu:latest "sleep 20000000" 41 seconds ago Up 40 seconds ad ubuntu:latest "/bin/bash" About a minute ago Up About a minute in exec -it dd5fe50ab712 /bin/bash 50ab712:/# ls dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var 50ab712:/# exit

Slide 61

Slide 61 text

Docker Volume “ A data volume is a specially- designated directory within one or more containers that bypasses the . Union File System

Slide 62

Slide 62 text

Docker Volume ~ $ ls /Users/baptou/myDirectory file1 file2 file3 ~ $ docker run -it -v /Users/baptou/myDirectory:/opt ubuntu:latest /bin/bash root@29088b02f260:/# ls /opt file1 file2 file3 root@29088b02f260:/# rm /opt/file2 root@29088b02f260:/# ls /opt file1 file3 root@29088b02f260:/# exit exit ~ $ ls /Users/baptou/myDirectory file1 file3 ~ $

Slide 63

Slide 63 text

Docker COMMIT ~ $ docker commit -h Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changes -a, --author="" Author (e.g., "John Hannibal Smith ") -c, --change=[] Apply specified Dockerfile instructions while committing the image -m, --message="" Commit message -p, --pause=true Pause container during commit

Slide 64

Slide 64 text

Docker COMMIT -d ubuntu /bin/bash -c "apt-get install -y hello" 123ee it -m "My first container with a Commit" 009e8061df58b8b123ee gilson/hello 5427d39bf6971f8415511fdaa3182a37869c14c4893664c43 es TAG IMAGE ID CREATED VIRTUAL SIZE latest b88f9422f14d 7 seconds ago 189.3 MB latest 34cd8b4a3d8b 4 weeks ago 163 MB ront latest 63a5a64ddc7a 4 weeks ago 163 MB front latest 63a5a64ddc7a 4 weeks ago 163 MB gilson/hello lists... ency tree... nformation... y the newest version. ewly installed, 0 to remove and 0 not upgraded. -it gilson/hello /bin/bash 9a:/# hello 9a:/# exit

Slide 65

Slide 65 text

Docker push ~ $ docker push -h Usage: docker push NAME[:TAG] Push an image or a repository to the registry --disable-content-trust=true Skip image signing

Slide 66

Slide 66 text

Docker push ~ $ docker push baptwaels/hello The push refers to a repository [baptwaels/hello] (len: 1) b88f9422f14d: Image push failed Please login prior to push: Username: baptwaels Password: Email: [email protected] WARNING: login credentials saved in /Users/baptou/.dockercfg. Login Succeeded The push refers to a repository [baptwaels/hello] (len: 1) b88f9422f14d: Image already exists 91e54dfb1179: Image successfully pushed d74508fb6632: Image successfully pushed c22013c84729: Image successfully pushed d3a1f33e8a5a: Image successfully pushed Digest: sha256:d659f9011eab6d04b3d9fd9f6324e23505bd1299c52d295c4b04ebe3e58878ce ~ $

Slide 67

Slide 67 text

Docker push

Slide 68

Slide 68 text

FROM ubuntu:latest RUN apt-get install vim -y Docker build Dockerfile ~ $ docker build -t myubuntu . ~ $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE myubuntu latest 4b205af179df 5 seconds ago 188.9 MB Shell

Slide 69

Slide 69 text

Docker system Usage: docker system COMMAND Manage Docker Options: --help Print usage Commands: df Show docker disk usage events Get real time events from the server info Display system-wide information prune Remove unused data Run 'docker system COMMAND --help' for more information on a command.

Slide 70

Slide 70 text

Docker system ~ $ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 8 5 1.296GB 729.3MB (56%) Containers 6 1 408B 345B (84%) Local Volumes 4 4 168.6MB 0B (0%) system df

Slide 71

Slide 71 text

Docker system ~ $ docker system df -v Images space usage: REPOSITORY TAG IMAGE ID CREATED ago (...) pen_banco latest 8e40d6a09c39 About an hour ago postgres 9.3 0dd7d39ff91b 2 days ago postgres latest ca3a55649cfc 2 days ago docker_apoiador-banco latest 556796db6132 4 days ago mdillon/postgis 9.5 95ef56d0b84b 6 days ago rabbitmq 3-management 281ee777b811 12 days ago hello-world latest 48b5124b2768 4 months ago jhipster/jhipster-registry v2.5.4 f5ac510b0620 6 months ago Containers space usage: CONTAINER ID IMAGE COMMAND LOCAL VOLUMES ( b484a4673c73 postgres:latest "docker-entrypoint..." 0 00515c9b728a docker_banco-teste "docker-entrypoint..." 1 25e7b744d869 docker_apoiador-banco "docker-entrypoint..." 1 8bb66b298716 rabbitmq:3-management "docker-entrypoint..." 1 6718c15a2bde jhipster/jhipster-registry:v2.5.4 "java -Djava.secur..." 1 ff1de954a916 hello-world "/hello" 0 Local Volumes space usage: VOLUME NAME LINKS SIZE 31f5e396aefc175501357305306bbb691243f9f41a98bb1aeca36d129d36c97f 1 2.597MB dc091727d965df0debed796e5381c47001ab8881141fde44fa578bb2a169850b 1 151.7kB e60cb462042b9b52800f019b13af1e7d49856d3f57ea7515d02eba5741960254 1 82.96MB 09212ad7c68f115564f0e5f06248df66458cf5618f814d17af67a400bc7aba52 1 82.93MB system df -v

Slide 72

Slide 72 text

Docker system ~ $ docker system prune WARNING! This will remove: - all stopped containers - all volumes not used by at least one container - all networks not used by at least one container - all dangling images Are you sure you want to continue? [y/N] system prune

Slide 73

Slide 73 text

Dockerfile “ A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

Slide 74

Slide 74 text

FROM ubuntu:latest # (...) Dockerfile Command FROM Sets the for subsequent instructions. As such, a valid Dockerfile must have FROM as its first instruction. The image can be any valid image – it is especially easy to start by pulling an image from the . Base Image Public Repositories

Slide 75

Slide 75 text

FROM ubuntu:latest MAINTAINER Gilson Filho # (...) Dockerfile Command MAINTAINER The MAINTAINER instruction allows you to set the Author field of the generated images.

Slide 76

Slide 76 text

FROM ubuntu:latest # MAINTAINER ... RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # Configure database and user... RUN ["mysql", "-u", "root", "-p"] Dockerfile Command RUN The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting comitted image will be used for the next step in the Dockerfile.

Slide 77

Slide 77 text

FROM ubuntu:latest # MAINTAINER ... RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # Configure database and user... CMD ["mysqld"] Dockerfile Command CMD The main purpose of a CMD is to provide defaults for an executing container. ​There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

Slide 78

Slide 78 text

FROM ubuntu:latest # MAINTAINER ... RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # Configure database and user... EXPOSE 3306 CMD ["mysqld"] Dockerfile Command EXPOSE The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. EXPOSE does not make the ports of the container accessible to the host.

Slide 79

Slide 79 text

FROM ubuntu:latest # MAINTAINER ... ENV MYSQL_MAJOR 5.7 RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # (...) Dockerfile Command ENV The ENV instruction sets the environment variable to the value . This value will be in the environment of all “descendant” Dockerfile commands and can be in many as well. replaced inline

Slide 80

Slide 80 text

FROM ubuntu:latest # MAINTAINER ... ENV MYSQL_MAJOR 5.7 RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # Configure database and user... ADD custom.conf /var/lib/mysql # (...) Dockerfile Command ADD The ADD instruction copies new files, directories or remote file URLs from and adds them to the filesystem of the container at the path .

Slide 81

Slide 81 text

FROM ubuntu:latest # MAINTAINER ... ENV MYSQL_MAJOR 5.7 RUN apt-get update # Other dependencies... RUN apt-get install -y mysql-server # Configure database and user... COPY custom.conf /var/lib/mysql # (...) Dockerfile Command COPY The COPY instruction copies new files or directories from and adds them to the filesystem of the container at the path .

Slide 82

Slide 82 text

FROM ubuntu:latest # MAINTAINER ... RUN apt-get update RUN apt-get install -y python-pip RUN pip install ipython ENTRYPOINT ["ipython"] Dockerfile Command ENTRYPOINT An ENTRYPOINT allows you to configure a container that will run as an executable.

Slide 83

Slide 83 text

CMD or ENTRYPOINT? 1. Dockerfile should specify at least one of CMD or ENTRYPOINT commands. 2. ENTRYPOINT should be defined when using the container as an executable. 3. CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container. 4. CMD will be overridden when running the container with alternative arguments.

Slide 84

Slide 84 text

FROM ubuntu:latest # (...) RUN mkdir /myvol RUN echo "hello world" > /myvol/greeting VOLUME /myvol Dockerfile Command VOLUME The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. The docker run command initializes the newly created volume with any data that exists at the specified location within the base image.

Slide 85

Slide 85 text

FROM ubuntu:latest RUN mkdir -p /var/whoami RUN chmod -R 777 /var/whoami RUN whoami >> /var/whoami/root.txt # Criando usuario RUN useradd basis -p 1234 USER basis RUN whoami >> /var/whoami/basis.txt Dockerfile Command USER The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.

Slide 86

Slide 86 text

FROM ubuntu:latest RUN pwd WORKDIR /opt RUN pwd RUN touch file_opt.txt WORKDIR /var RUN pwd RUN touch file_var.txt Dockerfile Command WORKDIR The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.

Slide 87

Slide 87 text

FROM ubuntu:latest # Other configurations... ONBUILD RUN echo "Echo message made by image base" Dockerfile Command ONBUILD The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after the FROM instruction in the downstream Dockerfile.

Slide 88

Slide 88 text

FROM ubuntu:latest # Other configurations... HEALTHCHECK --interval=5m --timeout=3s \ CMD curl -f http://localhost/ || exit 1 Dockerfile Command HEALTHCHECK The HEALTHCHECK instruction tells Docker how to test a container to check that it is still working. This can detect cases such as a web server that is stuck in an infinite loop and unable to handle new connections, even though the server process is still running.

Slide 89

Slide 89 text

Other commands https:/ /docs.docker.com/engine/reference/builder/

Slide 90

Slide 90 text

Orquestration

Slide 91

Slide 91 text

App Database link App link Storage link Storage link link

Slide 92

Slide 92 text

App Database link App link Storage link Storage link link Docker Host

Slide 93

Slide 93 text

Docker Host Docker Host Docker Host Docker Host

Slide 94

Slide 94 text

Orquestration “ Orchestration is a broad term that refers to the container scheduling, cluster management, and possibly the provision of additional hosts.

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

Tools Rancher Docker Swarm Fleet Kubernetes Mesos

Slide 98

Slide 98 text

Docker Compose “ Compose is a tool for defining and running multi-container Docker applications.

Slide 99

Slide 99 text

Docker Compose 1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere. 2. Define the services that make up your app in docker- compose.yml so they can be run together in an isolated environment. 3. Lastly, run docker-compose up and Compose will start and run your entire app.

Slide 100

Slide 100 text

version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress docker-compose.yml

Slide 101

Slide 101 text

web: build: . ports: - "5000:5000" volumes: - .:/code redis: image: redis Versions Compose files using the version 2 syntax must indicate the version number at the root of the document. Compose files that do not declare a version are considered “version 1”. docker-compose.yml version: '2' services: web: build: . ports: - "5000:5000" volumes: - .:/code redis: image: redis Version 1 Version 2

Slide 102

Slide 102 text

web: build: . # (...) Command BUILD Configuration options that are applied at build time. Can be specified either as a string containing a path to the build context, or an object with the path specified under and optionally and . context dockerfile args docker-compose.yml version: '2' services: web: build: context: ./app dockerfile: Dockerfile-alternate # (...)

Slide 103

Slide 103 text

version: '2' services: web: # hub.docker.com/_/ubuntu:latest image: ubuntu:latest # (...) Command IMAGE Specify the image to start the container from. Can either be a repository/tag or a partial image ID. docker-compose.yml version: '2' services: web: image: example-registry.com:4000/postgresql # (...)

Slide 104

Slide 104 text

Command VOLUME Mount paths or named volumes, optionally specifying a path on the host machine (HOST:CONTAINER), or an access mode (HOST:CONTAINER:ro). docker-compose.yml # (...) web: image: mysql:5.1 volumes: # Just specify a path and let the Engine create a volume - /var/lib/mysql # Specify an absolute path mapping - /opt/data:/var/lib/mysql # Path on the host, relative to the Compose file - ./cache:/tmp/cache # User-relative path - ~/configs:/etc/configs/:ro # Named volume - datavolume:/var/lib/mysql

Slide 105

Slide 105 text

Command VOLUME_FROM Mount paths or named volumes, optionally specifying a path on the host machine (HOST:CONTAINER), or an access mode (HOST:CONTAINER:ro). docker-compose.yml # (...) web: image: mysql:5.1 volumes: - /var/lib/mysql volumes_from: - service_name - service_name:ro - container:container_name - container:container_name:rw

Slide 106

Slide 106 text

Command ENVIRONMENT Add environment variables. You can use either an array or a dictionary. docker-compose.yml version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: - MYSQL_ROOT_PASSWORD=wordpress - MYSQL_DATABASE=wordpress - MYSQL_USER=wordpress - MYSQL_PASSWORD=wordpress

Slide 107

Slide 107 text

Command LINKS Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name. docker-compose.yml version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" environment: - MYSQL_ROOT_PASSWORD=wordpress - MYSQL_DATABASE=wordpress - MYSQL_USER=wordpress - MYSQL_PASSWORD=wordpress redis: # (...) web: image: wordpress:latest links: - db - redis

Slide 108

Slide 108 text

Command DEPENDS_ON Express dependency between services, which has two effects: docker-compose up will start services in dependency order. In the following example, db and redis will be started before web. docker-compose up SERVICE will automatically include SERVICE’s dependencies. In the following example, docker-compose up web will also create and start db and redis. docker-compose.yml version: '2' services: db: image: mysql:5.7 # (...) web: image: wordpress:latest depends_on: - redis - db

Slide 109

Slide 109 text

Command PORTS Expose ports. Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen). docker-compose.yml version: '2' services: wordpress: image: wordpress:latest ports: - "8000:80" version: '2' services: wordpress: image: wordpress:latest ports: - "3000" - "3000-3005" - "8000:8000" - "9090-9091:8080-8081" - "49100:22" - "127.0.0.1:8001:8001" - "127.0.0.1:5000-5010:5000-5010"

Slide 110

Slide 110 text

Command COMMAND Override the default command. docker-compose.yml version: '2' services: wordpress: image: wordpress:latest # Override 'CMD ["apache2-foreground"]' of wordpress Dockerfile command: bash ports: - "8000:80"

Slide 111

Slide 111 text

Command ENTRYPOINT Override the default entrypoint. docker-compose.yml version: '2' services: wordpress: image: wordpress:latest # Override 'CMD ["./entrypoint.sh"]' of wordpress Dockerfile entrypoint: ./custom-entrypoint.sh ports: - "8000:80"

Slide 112

Slide 112 text

Command ENV_FILE Add environment variables from a file. Can be a single value or a list. docker-compose.yml version: '2' services: wordpress: image: wordpress:latest ports: - "8000:80" env_file: .env version: '2' services: wordpress: image: wordpress:latest ports: - "8000:80" env_file: - ./common.env - ./apps/web.env - /opt/secrets.env

Slide 113

Slide 113 text

Command EXPOSE Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified. docker-compose.yml version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress expose: - "3306"

Slide 114

Slide 114 text

Command EXTENDS Extend another service, in the current file or another, optionally overriding configuration. docker-compose.yml web: extends: file: common-services.yml service: webapp webapp: build: . ports: - "8000:8000" volumes: - "/data" common-services.yml docker-compose.yml

Slide 115

Slide 115 text

Resources

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

https://www.pluralsight.com/browse/it-ops/docker

Slide 118

Slide 118 text

Examples https:/ /github.com/gilsondev/workshop-docker

Slide 119

Slide 119 text

Getting Started https:/ /docs.docker.com/get-started​

Slide 120

Slide 120 text

Raffle!

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Vale Presente Casa do Código

Slide 123

Slide 123 text

Email: [email protected] Blog: Telegram/Github: @gilsondev Twitter: gilsondev.in @gilsonfilho Questions? Forked on: