Workshop Docker

Workshop Docker

Apresentação do que é o Docker, porque foi feito, e seu uso básico para o dia a dia.

054d9fa364a9f7db6985df0645b21b42?s=128

Gilson Filho

June 06, 2017
Tweet

Transcript

  1. Docker Gilson Filho

  2. Alert!

  3. Slides with this ↑ show updates about Docker and your

    ecosystem
  4. What is

  5. Docker Begins

  6. None
  7. None
  8. None
  9. None
  10. What is Docker ? “ Docker is an open platform

    for building, shipping and running distributed applications. docker.io
  11. What is Docker ?

  12. None
  13. None
  14. An open framework to assemble specialized container systems without reinventing

    the wheel. Moby
  15. Going forward, Docker will be assembled using Moby, see for

    more details. Moby and Docker Moby
  16. What is Docker Moby ?

  17. Back to THE 90's

  18. MY APP + A REAL Server =

  19. VIRTUAL MACHINEs

  20. VIRTUAL MACHINEs

  21. VIRTUAL MACHINEs

  22. Docker containers

  23. Docker containers

  24. Docker containers VM Docker

  25. LXC = OS-level virtualization for running multiple isolated Linux systems

    "LINUX CONTAINERS"
  26. cgroups = Linux kernel feature that limits and isolates the

    resource usage (CPU, disk I/O, network, etc.) "CONTROL GROUPS"
  27. 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"
  28. Docker > 1.11 Engine is now built on runC and

    containerd
  29. None
  30. How to Install

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

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

  33. 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/

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

  35. Windows

  36. OS X

  37. Docker HUB

  38. Over 1.2B Pulls from Docker Hub 5.6M 65 240K Pulls

    per Day Pulls per Second Repositories on Docker Hub
  39. Docker Store next generation of Docker Hub

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

  41. Dictionary

  42. 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.
  43. 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.
  44. Docker Commands

  45. 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
  46. 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
  47. 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
  48. 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 ~ $
  49. 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) [...]
  50. 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 ~ $
  51. 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 ~ $
  52. 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
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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
  58. 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: <name|uid>[:<group|gid>])
  59. 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
  60. 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
  61. Docker Volume “ A data volume is a specially- designated

    directory within one or more containers that bypasses the . Union File System
  62. 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 ~ $
  63. 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 <hannibal@a-team.com>") -c, --change=[] Apply specified Dockerfile instructions while committing the image -m, --message="" Commit message -p, --pause=true Pause container during commit
  64. 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
  65. 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
  66. 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: bwaels@gmail.com 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 ~ $
  67. Docker push

  68. 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
  69. 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.
  70. 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
  71. 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
  72. 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
  73. Dockerfile “ A Dockerfile is a text document that contains

    all the commands a user could call on the command line to assemble an image.
  74. 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
  75. FROM ubuntu:latest MAINTAINER Gilson Filho <gilson.filho@basis.com.br> # (...) Dockerfile Command

    MAINTAINER The MAINTAINER instruction allows you to set the Author field of the generated images.
  76. 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.
  77. 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.
  78. 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.
  79. 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 <key> to the value <value>. This value will be in the environment of all “descendant” Dockerfile commands and can be in many as well. replaced inline
  80. 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 <src> and adds them to the filesystem of the container at the path <dest>.
  81. 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 <src> and adds them to the filesystem of the container at the path <dest>.
  82. 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.
  83. 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.
  84. 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.
  85. 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.
  86. 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.
  87. 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.
  88. 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.
  89. Other commands https:/ /docs.docker.com/engine/reference/builder/

  90. Orquestration

  91. App Database link App link Storage link Storage link link

  92. App Database link App link Storage link Storage link link

    Docker Host
  93. Docker Host Docker Host Docker Host Docker Host

  94. Orquestration “ Orchestration is a broad term that refers to

    the container scheduling, cluster management, and possibly the provision of additional hosts.
  95. None
  96. None
  97. Tools Rancher Docker Swarm Fleet Kubernetes Mesos

  98. Docker Compose “ Compose is a tool for defining and

    running multi-container Docker applications.
  99. 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.
  100. 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
  101. 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
  102. 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 # (...)
  103. 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 # (...)
  104. 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
  105. 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
  106. 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
  107. 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
  108. 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
  109. 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"
  110. 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"
  111. 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"
  112. 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
  113. 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"
  114. 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
  115. Resources

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

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

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

  120. Raffle!

  121. None
  122. Vale Presente Casa do Código

  123. Email: me@gilsondev.in Blog: Telegram/Github: @gilsondev Twitter: gilsondev.in @gilsonfilho Questions? Forked

    on: