O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Docker for mere mortals

623 visualizações

Publicada em

Docker for mere mortals

Publicada em: Tecnologia
  • Entre para ver os comentários

Docker for mere mortals

  1. 1. Broughttoyou byHenrykKonsek Docker For mere mortals.
  2. 2. hekonsek@gmail.com | @hekonsek
  3. 3. ● What is Docker ● Background ● Key concepts + first steps ● Layers ● Publishing images ● Volumes ● Networking ● Good practices This session
  4. 4. What is Docker
  5. 5. Server for running and managing Linux containers. What is...
  6. 6. Operating-system-level virtualization. What are Linux containers?
  7. 7. chroot on steroids + some kernel magic What are Linux containers?
  8. 8. ● slooooooow ● gigantic images ● aggressive resource allocation ● bad API Why not regular virtualization?
  9. 9. Background
  10. 10. Created by this dude Solomon Hykes
  11. 11. Based on LXC Docker team created their own LXC using Go.
  12. 12. Key concepts + first steps
  13. 13. Container is the running image. Key concepts ● image (immutable, no state) ● container (mutable, has state)
  14. 14. Container is the running image. Key concepts
  15. 15. Archived filesystem + metadata. Docker image
  16. 16. No memory snapshots! Docker image
  17. 17. Like Git, but for containers. Commands
  18. 18. Install Docker on Ubuntu. Before you start $ curl -sSL https://get.docker.com/ | sh $ service docker start $ docker version
  19. 19. Let’s run Dockerized shell in new container. Dockerized shell using base image $ docker run -it ubuntu /bin/bash
  20. 20. Docker container == pimped Unix process
  21. 21. Start ‘top’ process in Docker. See/kill it from the host. Docker container == pimped Unix process $ docker run -it ubuntu /bin/bash $ top $ ps aux | grep top $ sudo kill -9 <TOP_PID>
  22. 22. Let’s run daemon process in the new container. Daemon process using base image $ docker run -it ubuntu /usr/bin/top
  23. 23. Let’s run daemon process in the backgronud. Then kill it. Background daemon process using base image $ docker run -d -it ubuntu /usr/bin/top $ docker ps $ docker stop <containerId> $ docker start <containerId>
  24. 24. Tail into the running process. See background process output $ docker run -d -it ubuntu /usr/bin/top $ docker ps $ docker logs -f <containerId>
  25. 25. Layers
  26. 26. Layers WAR Tomcat JRE Ubuntu base
  27. 27. Let’s containerize the execution of process. Dockerized command execution FROM ubuntu RUN apt-get update -qqy RUN apt-get install -qqy cowsay ENTRYPOINT ["/usr/games/cowsay"] CMD ["I'm development cow!"] '' $ docker build -t mycow . $ docker run -t mycow $ docker run -t mycow 'I am production cow!'
  28. 28. Copy and display host’s fstab. Add files to the container FROM ubuntu ADD fstab /tmp/copied_fstab ENTRYPOINT ["cat", "/tmp/copied_fstab"] $ docker build -t fstaber . $ docker run -t fstaber $ cp /etc/fstab fstab
  29. 29. Publishing images
  30. 30. Just like Git repositories :) . Registries.
  31. 31. Create your DockerHub (http://hub.docker.com) account. Before we start
  32. 32. Push to the DockerHub with the latest tag. Push to the DockerHub registry docker login docker build -t hekonsek/test:1 . docker tag -f hekonsek/test:1 hekonsek/test:latest docker push hekonsek/test
  33. 33. Volumes
  34. 34. How can containers share the file system?
  35. 35. You can share filesystem between host and containers. Mounting host filesystem $ docker run -v /etc:/etc-from-host -it ubuntu /bin/bash $ ls /etc-from-host
  36. 36. Provided by the database community/vendor. How can I get database image? $ docker run -d -p 27017:27017 --name mongodb mongo $ apt-get install mongodb-clients $ mongo ]
  37. 37. Mount volume container. Mounting volumes docker run -v /data/db --name mongodb_data busybox true docker run -d --volumes-from mongodb_data -p 27017:27017 --name mongodb mongo
  38. 38. Browse data from the volume. Mounting volumes $ docker run --volumes-from mongodb_data -it ubuntu /bin/bash $ ls /data/db
  39. 39. Create backup of the MongoDB data. Backups $ docker run --volumes-from mongodb_data -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data
  40. 40. Networking
  41. 41. ip a | grep docker Virtual ethernet bridge
  42. 42. Containers can access Internet. Internet can’t access containers. Containers are behind of kinda NAT
  43. 43. Docker server can forward ports from containers. Remember MongoDB? $ docker run -d -p 27017:27017 --name mongodb mongo
  44. 44. Let the cow count items in collection using linked MongoDB. How container A can access the network of container B? $ docker run --link mongodb:mongodb -it ubuntu /bin/bash $ apt-get update -qqy $ apt-get install -qqy mongodb-clients $ apt-get install -qqy cowsay $ echo 'db.foo.count()' | mongo mongodb:27017 | /usr/games/cowsay
  45. 45. Kubernetes for the rescue. Networking is hard
  46. 46. Good practices
  47. 47. The generic approach to connect to the service from your application. Connections failover env:MONGODB_SERVICE_HOST # Kubernetes / Custom mongodb # linked container localhost # localhost
  48. 48. The order of the instructions in Dockerfile is important. Build with the caching in mind $ docker build ...
  49. 49. Immutable deployment. Use ENV variable to the container. Build once. Run everywhere.
  50. 50. Docker Maven plugin by Roland ‘Jolokia’ Huß How can I put a fresh jar into an image?
  51. 51. How can I put a fresh jar into an image? <image> <name>${project.artifactId}:${project.version}</name> <build> <from>hekonsek/fatjar:0.0.10-SNAPSHOT</from> <assemblyDescriptorRef>artifact</assemblyDescriptorRef> <exportDir>/jars</exportDir> </build> </image> mvn docker:buid docker:push
  52. 52. docker rmi $(docker images -q) Remove images from time to time :)
  53. 53. Thank you!

×