Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[deSymfony] Docker on every environment

Jose Armesto
September 16, 2016

[deSymfony] Docker on every environment

Jose Armesto

September 16, 2016
Tweet

More Decks by Jose Armesto

Other Decks in Programming

Transcript

  1. You take the red pill, you stay in Wonderland, and

    I show you how deep the rabbit hole goes.
  2. ❏ Disk images .iso ❏ VMware .vdmk ❏ Vagrant .box

    ❏ Amazon Machine Images AMI Systems Packaging
  3. The difference between how you think something works and how

    it actually works risks hard-to-debug production issues. Gareth Rushgrove @garethr
  4. ❏ Which OS is it based on? ❏ Which packages

    are installed? ❏ What application is running inside? Giving a running container
  5. ❏ Which OS is it based on? ❏ Which packages

    are installed? ❏ What application is running inside? Giving a running container
  6. Operating System Tags can be overwritten! 3.4 won’t be the

    same in two weeks, probably FROM  alpine:3.4 CMD  [“echo”,  “Knock”,  ”Knock”,  “Neo”]
  7. ❏ Which OS is it based on? ❏ Which packages

    are installed? ❏ What application is running inside? Giving a running container
  8. Packages Which pip? FROM  alpine:3.4 RUN  apk  add  -­‐-­‐update  py-­‐pip

    CMD  [“echo”,  “Knock”,  ”Knock”,  “Neo”]
  9. Versions Specify the version FROM  alpine:3.4 RUN  apk  add  -­‐-­‐update

     py-­‐pip=8.1.2-­‐r0 CMD  [“echo”,  “Knock”,  ”Knock”,  “Neo”]
  10. ❏ Which OS is it based on? ❏ Which packages

    are installed? ❏ What application is running inside? Giving a running container
  11. Application Which version of our application? FROM  alpine:3.4 RUN  apk

     add  -­‐-­‐update  py-­‐pip=8.1.2-­‐r0 COPY  app.py  /app.py CMD  [“python”,  “/app.py”]
  12. Metadata Use Docker Labels for application metadata FROM  alpine:3.4 ARG

     vcs_ref="Unknown" ARG  build_date="Unknown" RUN  apk  add  -­‐-­‐update  py-­‐pip=8.1.2-­‐r0 LABEL  org.label-­‐schema.vcs-­‐ref=$vcs_ref  \ org.label-­‐schema.build-­‐date=$build_date COPY  app.py  /app.py CMD  [“python”,  “/app.py”]
  13. Metadata Use Docker Labels for application metadata FROM  alpine:3.4 ARG

     vcs_ref="Unknown" ARG  build_date="Unknown" RUN  apk  add  -­‐-­‐update  py-­‐pip=8.1.2-­‐r0 LABEL  org.label-­‐schema.vcs-­‐ref=$vcs_ref  \ org.label-­‐schema.build-­‐date=$build_date COPY  app.py  /app.py CMD  [“python”,  “/app.py”]
  14. Metadata Use Docker Labels for application metadata FROM  alpine:3.4 ARG

     vcs_ref="Unknown" ARG  build_date="Unknown" RUN  apk  add  -­‐-­‐update  py-­‐pip=8.1.2-­‐r0 LABEL  org.label-­‐schema.vcs-­‐ref=$vcs_ref  \ org.label-­‐schema.build-­‐date=$build_date COPY  app.py  /app.py CMD  [“python”,  “/app.py”]
  15. Metadata Calculate the values for the labels $  docker  build

     \ -­‐-­‐build-­‐arg  vcs_ref=`git  rev-­‐parse  HEAD`  \ -­‐-­‐build-­‐arg  date=`date  -­‐u  +  "%Y-­‐%m-­‐%dT%H:%MZ"`  \ -­‐t  your_image_name  .
  16. Jenkins Workflow 1. Detect merge to repository 2. If tests

    pass, build image and push it to pre production registry
  17. Jenkins Workflow 1. Detect merge to repository 2. If tests

    pass, build image and push it to pre production registry 3. Deploy to pre environment
  18. Jenkins Workflow 1. Detect merge to repository 2. If tests

    pass, build image and push it to pre production registry 3. Deploy to pre environment 4. If tests pass, push image to pro registry
  19. Jenkins Workflow 1. Detect merge to repository 2. If tests

    pass, build image and push it to pre production registry 3. Deploy to pre environment 4. If tests pass, push image to pro registry 5. Deploy to production
  20. Keep In Mind ❏ Be clear on which versions of

    docker/docker-compose you allow ❏ Use Jenkins build number or timestamp as image tag ❏ Seek a Generic Build process ❏ Clean old images/containers
  21. ❏ Easier debugging ❏ Simplified setup of networks, ports... ❏

    Logs have only one format ❏ Resources sharing: CPU vs memory Running one process
  22. ❏ How they start? ❏ How they stop? Containers and

    processes share a similar lifecycle
  23. When you run the container, the init (PID1) process is

    started, which is responsible for starting other processes, creating a tree-like hierarchy.
  24. $  ps -­‐e  -­‐o  user,pid,ppid,args -­‐-­‐forest UID   PID  

    PPID   CMD root   1   0   init root   205   1 /sbin/udevd -­‐-­‐daemon root    1113    205 \_  /sbin/udevd -­‐-­‐daemon root    1114    205   \_  /sbin/udevd -­‐-­‐daemon root    1199   1 crond -­‐f  -­‐d  8 root    1216   1 VBoxService root    1241   1 /usr/local/sbin/acpid root    1249   1 /sbin/udhcpc -­‐b  -­‐i eth1...
  25. When a process ends, its entry in the process table

    remains, keeping the process in a defunct or zombie status.
  26. Only after the parent read the child’s exit status to

    know what happened, the zombie is removed. This is called reaping.
  27. The init process also adopts orphans. An orphan is a

    process that is still executing but whose parent has died.
  28. If your process is running as PID1, it’s probably expecting

    a init process to properly adopting and reaping processes.
  29. Running our process as a subcommand of bash would solve

    this problem. But bash doesn’t handle unix signals.
  30. A signal is an asynchronous notification sent to a process

    in order to notify it of an event that occurred.
  31. Unless a process has registered a custom signal handler for

    SIGTERM, the kernel will fall back sending a SIGKILL signal.
  32. For PID1, though, the kernel won’t even fall back to

    SIGKILL. If your process hasn’t registered a handler, SIGTERM will have no effect on the process.
  33. By default, docker stop sends a SIGTERM and waits 10

    seconds for the container to stop. After that, it sends a SIGKILL.
  34. shell form ❏ ENTRYPOINT  command  param1  param2 ❏ The process

    will be started as a subcommand of /bin/sh -c ❏ Remember, bash does not pass signals
  35. exec form ❏ ENTRYPOINT  ["executable",  "param1"] ❏ The process will

    be PID1 init process inside the container ❏ Your process should adopt and take care of reaping
  36. Using a proper init process ❏ A init process that

    pass signals, adopt orphans and takes care of reaping. ❏ There are several init processes for containers ❏ tini ❏ dumb-init
  37. Without a proper init system ❏ Zombie processes could become

    a problem in the system. ❏ Signals are not passed to your process as you may expect, not being able to gracefully stop a process.