Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Docker Intro

283 views

Published on

Slides for an introductory presentation on Docker

Published in: Education
  • Be the first to comment

Docker Intro

  1. 1. An Introduction to Docker 1 Ruben Taelman - @rubensworks imec - Ghent University
  2. 2. So what is Docker? Platform for running software in isolated containers 2
  3. 3. So what is Docker? Platform for running software in isolated containers 3 Traditional webserver NGINX PostgreSQL Node
  4. 4. So what is Docker? Platform for running software in isolated containers 4 Traditional webserver Docker webserver NGINX PostgreSQL Node NGINX PostgreSQL Node
  5. 5. So what is Docker? Platform for running software in isolated containers 5 Traditional webserver Docker webserver NGINX PostgreSQL Node NGINX PostgreSQL Node ✓Linux ✓Windows ✓Mac
  6. 6. (Reproducible) software evaluations Easily installable and disposable software Running different software versions simultaneously What to use Docker for? 6
  7. 7. Overview Basics Networks Convenience tools 7
  8. 8. Overview Basics Networks Convenience tools 8
  9. 9. Virtual machines vs containers (Docker) containers don’t need separate OS’s, so they are more lightweight. 9
  10. 10. Docker workflow 10 Dockerfile Image Container Build Run Description of an image Built image Available for reuse Instantiated image
  11. 11. Dockerfile Layered image descriptions 11 Debian Node JS LDF server
  12. 12. 12 # Inherit from the Node 4.2.2 image FROM node:4.2.2 # Copy the server files ADD . /app # Install the node module RUN cd /app && npm install # Expose the default port EXPOSE 3000 # Run base binary ENTRYPOINT ["node", "bin/ldf-server"] # Default command CMD ["--help"] > cat Dockerfile
  13. 13. RUN Executed when the image is being built Zero or more RUN’s per Dockerfile Typically used for installing software Result will be stored in image CMD Executed when the image is being run/instantiated Only one CMD per Dockerfile Default command to run when starting the container Can be overridden by user ! Difference between RUN and CMD ! 13
  14. 14. Build image to your local repository Building a Dockerfile to an image 14 > docker build -t <image-name> <path-to-dir>
  15. 15. All your available images Your local image repository 15 > docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ldf-server latest db3a7fb38cb2 10 minutes ago 683.3 MB stuff latest do89d002jbsd 1 week ago 102.2 MB
  16. 16. http://hub.docker.com Reuse existing images 16
  17. 17. Search the Docker hub, and download images to your local repo Or use the command-line... 17 > docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 4958 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 67 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 47 [OK] > docker pull ubuntu 12.04: Pulling from library/ubuntu ba2b457ecfb2: Pull complete 26180b0fe8fb: Pull complete edd7c1974a70: Pull complete 57bca5139a13: Pull complete library/ubuntu:12.04: The image you are pulling has been verified. Status: Downloaded newer image for ubuntu:12.04
  18. 18. Instantiate an image Running an image 18 > docker run -it --rm ldf-server Important options: -i -t --rm -d -p 8080:80 -v /mydir:/targetdir ... Keep STDIN open Allocate new terminal Remove container after stopping (default: stopped state) Run in background Map host port to container port Map local directory to container directory
  19. 19. List running containers List running + stopped containers Stop container Remove container List images Remove image Image and container management 19 docker ps docker ps -a docker stop <container-hash-or-name> docker rm <container-hash-or-name> docker images docker rmi <image-name>
  20. 20. Attach an image (not guaranteed to have a CLI) Using detached containers 20 > docker attach <container-hash> Open shell in container (useful for debugging) > docker exec -it <container-hash> /bin/bash CTRL+p CTRL+q to detach
  21. 21. Overview Basics Networks Convenience tools 21
  22. 22. Connect microservices using virtual Docker networks 22 Docker webserver NGINX PostgreSQL Node
  23. 23. Managing networks 23 > docker network ls NETWORK ID NAME DRIVER 7fca4eb8c647 bridge bridge 9f904ee27bf5 none null cf03ee007fb4 host host Default Dummy network Same as host network > docker network create --driver bridge <network-name> > docker network inspect <network-name> > docker run --network=<network-name> <image-name>
  24. 24. using Docker swarm Swarm Running containers on multiple hosts 24 Manager Node 1Node 0 Node 2
  25. 25. Scale applications, by running containers N times Load balancing Automatic management Deploying applications in clusters 25
  26. 26. Scale applications, by running containers N times Load balancing Automatic management Deploying applications in clusters 26
  27. 27. Overview Basics Networks Convenience tools 27
  28. 28. Docker Compose Declaratively define multi-container applications in docker-compose.yml 28 > docker-compose up -d > docker-compose stop > docker-compose rm
  29. 29. 29 version: '2' services: server: image: linkeddatafragments/server.js ports: - "3000:3000" volumes: - ${DATA_DIR}:/data - ./config-server.json:/tmp/config.json command: /tmp/config.json 3000 ${LDF_WORKERS} server-cache: image: nginx:stable ports: - "80:80" volumes: - ./nginx-default:/etc/.../default:ro links: - server > cat docker-compose.yml
  30. 30. Docker Machine Install Docker Engine on any host Easily SSH to any host to control it 30
  31. 31. Methods for measuring CPU, memory usage, I/O … Third-party alternatives: Datadog, CAdvisor, Scout ... Monitoring 31 > docker stats CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O 1285939c1fd3 0.07% 796 KiB / 64 MiB 1.21% 788 B / 648 B 3.568 MB / 512 KB 9c76f7834ae2 0.07% 2.746 MiB / 64 MiB 4.29% 1.266 KB / 648 B 12.4 MB / 0 B d1ea048f04e4 0.03% 4.583 MiB / 64 MiB 6.30% 2.854 KB / 648 B 27.7 MB / 0 B
  32. 32. Overview Basics Networks Convenience tools 32

×