Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Docker in everyday development

Docker in everyday development, most important commands in Docker CLI, using Docker-Compose, combining Docker with Makefile. Tips for troubleshooting.

  • Identifiez-vous pour voir les commentaires

Docker in everyday development

  1. 1. Docker in everyday development What every dev should know.
  2. 2. Justyna Ilczuk, Senior Software / DevOps Engineer at Speaker A scalable backend that helps developers build complex apps with only front-end code. http://www.syncano.com/
  3. 3. Docker - An open platform for distributed applications for developers and sysadmins. * Powered by Linux Containers. Build, Ship and Run Any App, Anywhere
  4. 4. Why?
  5. 5. Why? Portability rocks! App works on all machines (not only on mine!)
  6. 6. Why? Isolate and version dependencies on both language and OS level - better than virtualenv (rvm)
  7. 7. Why? Build Dev Environment than resembles production environment - avoid strange bugs from dev/prod mismatch
  8. 8. Why? Installing dockerized services is trivial - You need a Postgres in version 9.4? Or redis, or Rabbitmq, Elastic Search? Just pull an image and start a container.
  9. 9. Still not convinced?
  10. 10. Docker pros Lightweight ● busybox - 2.433 MB ● debian - 85.01 MB ● nginx - 91.66 MB ● redis - 111.2 MB
  11. 11. Docker pros Unified build process Dockerfile FROM debian:latest RUN apt-get update && apt-get install tmux CMD tmux $ docker build -t my_image .
  12. 12. Docker pros Docker image format, portability, hub $ docker pull organization/image_name $ docker run -it organization/image_name command $ docker push me/my_image
  13. 13. Docker pros Fast, starting container in 0.2 s $ time docker run --rm ubuntu /bin/echo hello world hello world docker run --rm ubuntu /bin/echo hello world 0,02s user 0,01s system 9% cpu 0,271 total
  14. 14. Docker pros - summing up ● lightweight containers ● unified build process (Dockerfile) ● standardized images (Docker hub) ● fast, starting container in 0.2 s ● combining containers together ● distributed apps, microservices
  15. 15. Docker cons ● works only on GNU/Linux (needs vagrant / boot2docker) ● new tool to learn ● another layer of complexity & overhead - vagrant + Docker vs developing natively on your machine
  16. 16. Docker + Vagrant Containers on VMs
  17. 17. Docker + Vagrant ● Works everywhere ● Possible to try new tech, new OSes ○ CoreOS ○ Kubernetes ○ Mesos ○ etcd ○ Consul ● Distributed apps on your laptop
  18. 18. https://www.flickr.com/photos/110382334@N05/11303036263
  19. 19. Tools ● Docker CLI ● Docker compose (aka fig) ● Good old make
  20. 20. Docker CLI - the most important command Running containers $ docker run --rm ubuntu echo “Hello docker” $ docker run -d -p 8080:80 nginx $ docker run -it -v `pwd`:/app -p 8000:8000 my_app
  21. 21. Docker CLI - checking state Checking state of containers $ docker ps $ docker images $ docker logs my_container $ docker top my_container
  22. 22. Docker CLI https://docs.docker. com/reference/commandline/cli/ $ docker --help $ man docker 37 commands (for everything and more)
  23. 23. https://www.flickr.com/photos/pasukaru76/9824401426/in/photolist-9DE7Wa-cd6Wxf-dLkpKN-bW4iP-6TfKoP-okpdNP- fY9Cgu-8SBNJB-7vgLWL-a5sj6k-3SUkNL-koVXTM-8vs4F6-EmbdC-6w5kAz-i9E5k-878gAY-e88nnZ-9dDY7N-4uNsCX- 7iuh42-fMEpmV-pybGg-bF1XGL-6cyxFq-tauEV-7zWj8-eewWz-a24hkr-4EjNgb-o4yuXd-f4PmxD-9bCZC5-e69XkS- dgEs3y-4jYxpy-6Qfw98-aB4Vgf-4gm9N6-jySVXM-dVJKrK-cu4nm3-jN6RPH-8W5ooc-4pAwWe-8TpRWe-77os7A- 5256km-3NdDg2-6KipNW
  24. 24. Containers everywhere $ docker rmi $ docker rm
  25. 25. Time for a better tool Docker Compose
  26. 26. Docker Compose Compose is a tool for defining and running complex applications with Docker.
  27. 27. Docker Compose ● Define your containers in simple yaml file. ● Compose container together. ● Manage group of containers with single tool.
  28. 28. Demo of Docker Compose
  29. 29. Docker Compose - config docker-compose.yml redis: image: redis volumes: - /var/docker/redis:data ports: - "6379" web: build: . ports: - "80:8080" links: - redis:redis volumes: - .:/app environment: - VARIABLE=value
  30. 30. Docker Compose - config redis: image: redis volumes: - /var/docker/redis:data ports: - “6379”
  31. 31. Docker Compose - config web: build: . ports: - "8090:8080" links: - redis:redis volumes: - .:/app environment: - VARIABLE=value
  32. 32. Docker Compose - commands $ docker-compose build $ docker-compose up $ docker-compose ps
  33. 33. Docker Compose https://docs.docker.com/compose/ https://docs.docker.com/compose/yml/ https://github.com/docker/compose Example: http://www.syncano.com/configuring-running- django-celery-docker-containers-pt-1/
  34. 34. All is rainbows and unicorns now, right?
  35. 35. Compose - good for running containers But missing dependencies.
  36. 36. Updating images ● Developers Bob and Alice work on an App. ● They use docker-compose to run App ● Bob adds new feature that requires Dependency X to be baked into Docker image ● He updates the requirements.txt file that is used in Dockerfile and rebuilds his image
  37. 37. Updating images ● Cool feature is merged to trunk ● Alice pulls changes ● Alice starts docker-compose and app breaks, because of missing dependency in the container
  38. 38. Technical of people problem? Should Alice remember to run `docker- compose build`, `docker-compose rm` and `docker-compose up` after each pull?
  39. 39. Automate everything. Use smart technologies. Use Make.
  40. 40. Good ol’ Makefile run : build docker-compose up -d build : .built .built : requirements.txt Dockerfile docker-compose build touch .built stop : docker-compose stop clean : stop docker-compose rm rm .built test : .built docker-compose run web ./run_tests.sh ${ARGS} .PHONY : run build clean stop test
  41. 41. Good ol’ Makefile run : build docker-compose up -d build : .built .built : requirements.txt Dockerfile docker-compose build touch .built
  42. 42. Makefile ● Uses docker-compose ● Best for dependencies ● Self documenting
  43. 43. Other problems that you might encounter
  44. 44. Ups… something went wrong. Building image failed. - it stops at layer that failed - starts from the last correct layer (cache)
  45. 45. Ups… something went wrong. App in containers behaves in a strange way: Logs and errors - logging to stdout - logging to volumes - logging straight to Centralized Logging - logging to sentry
  46. 46. Ups… something went wrong. https://github.com/slafs/sentry-docker <3
  47. 47. Ups… something went wrong. Operating on a live patient - Debugging running containers - no need for ssh - … no need for nsenter - $ docker exec -it my_container bash
  48. 48. Questions? @attilczuk

×