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

Docker Workshop

ProdOps
June 10, 2014

Docker Workshop

Introduction to Docker workshop
http://www.meetup.com/Docker-Tel-Aviv/events/219060445/

This workshop covers Docker basics. You will progress from introductory hands-on experience using ready containers up to creating custom images, monitoring and troubleshooting interlinked containers. Learn the concepts and terminology used by Docker to describe infrastructure and more. You will leave with the skills and confidence to use Docker in a wide range of settings.

ProdOps

June 10, 2014
Tweet

More Decks by ProdOps

Other Decks in Technology

Transcript

  1. > git clone https://gist.github.com/dfece549c22ddd3eccad workshop > cd workshop > vagrant

    up > vagrant ssh > docker --version bootstrap #DB001 cheat sheet dvps.me/docker-ws-cheat Docker version 1.3.3, build d344625
  2. After 1956, using containers, it cost ¢16 per ton to

    load a ship. Containerization greatly reduced the time to load and unload cargo. Malcom Purcell McLean "A ship earns money only when she is at sea".
  3. static website user data web frontend queue analytics development environments

    qa servers customer data center public cloud production cluster
  4. > git clone https://gist.github.com/dfece549c22ddd3eccad workshop > cd workshop > vagrant

    up > vagrant ssh > docker --version bootstrap #DB001 cheat sheet dvps.me/docker-ws-cheat Docker version 1.3.3, build d344625
  5. > docker run busybox /bin/echo ‘Hello World!’ Hello World! hello

    world! #DB002 image command to run output dvps.me/docker-ws-cheat
  6. dvps.me/docker-ws-cheat > docker run --tty --interactive busybox /bin/sh / #

    exit interactive container #DC001 keep stdin attached
  7. $ uname -a # show kernel/linux version $ pwd #

    show current directory $ ls # show files in directory $ whoami # what is my user name $ id # what is my user id $ ps # what processes are running $ hostname # what is the server hostname $ ifconfig # network interface list $ netstat # network activity $ netstat -r # routing table $ mount # mounted file systems inspecting a linux environment dvps.me/docker-ws-cheat
  8. > docker run -t -i -e PS1='\u@\h:\w# ' busybox /bin/sh

    root@abcdef:/# uname -a root@abcdef:/# pwd root@abcdef:/# ls root@abcdef:/# whoami root@abcdef:/# id root@abcdef:/# ps root@abcdef:/# hostname root@abcdef:/# ifconfig root@abcdef:/# netstat root@abcdef:/# netstat -r root@abcdef:/# mount interactive container environment variable dvps.me/docker-ws-cheat
  9. > docker run -ti busybox \ /bin/sh -c 'while true;

    do date; sleep 1; done' docker being a clock dvps.me/docker-ws-cheat
  10. > docker run -d busybox \ /bin/sh -c 'while true;

    do date; sleep 1; done' e04e6a90bd09723fcda724ecd9392434992d7d0fd335bb465cd5f618570ee68e daemon clock! Hey! Where is the REAL output? dvps.me/docker-ws-cheat
  11. > docker ps > docker top container_name_or_id > docker logs

    container_name_or_id > docker stop container_name_or_id > docker start container_name_or_id > docker rm container_name_or_id running containers dvps.me/docker-ws-cheat CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d40ad71102b8 busybox:latest /bin/sh -c 'while tr 2 minutes ago Up 2 minutes berserk_hopper
  12. > docker inspect container_name # filtering a single property (using

    GO text/template) > docker inspect -f '{{ .NetworkSettings.IPAddress }}' cont_name container metadata dvps.me/docker-ws-cheat
  13. > docker run -d busybox \ nc -ll -p 80

    -e /bin/echo -e "HTTP/1.1 200 OK\n\nHello World!\n" > docker inspect `docker ps -ql` | grep IPAddress > curl http://<ip_address> a hello-world web server dvps.me/docker-ws-cheat
  14. containers : what we learned so far ✓ running commands

    in a container ✓ starting interactive containers ✓ namespace separation ✓ containers with daemons ✓ inspecting live containers ✓ container metadata ✓ docker bridge networking
  15. Challenge - containers Start a container that replies with a

    list of environment variables to http requests. Five names and values, one per line. eg. curl http://container_ip_address/ PWD=/ HOSTNAME=abcadb123 ...
  16. > docker run -d busybox \ nc -ll -p 80

    -e \ /bin/sh -c \ "/bin/echo -e 'HTTP/1.1 200 OK\n'; /usr/bin/env | head -5" environment-replying web server dvps.me/docker-ws-cheat
  17. en.wikipedia.org/wiki/SS_Ideal_X on April 26, 1956 the Ideal X carried 58

    containers from Port Newark, New Jersey, to Port of Houston, Texas, where 58 trucks were waiting to be loaded with the containers.
  18. # single most important command in docker > docker help

    # combine single character options : -t -i > docker run -ti # boolean options have defaults when not used : -d=false > docker run -d # multi options can be used more than once : -a=[] > docker run -a stdin -a stdout -a stderr # options with values : --name=”” -c=0 > docker run --name bigbox -c 0 docker cli docs.docker.com/reference/commandline/cli/
  19. > docker run -ti busybox /bin/sh / # cat >

    bin/server.sh #!/bin/sh PATH=/bin:/usr/bin nc -ll -p 80 -e echo -e "HTTP/1.1 200 OK\n\nI am very FAST!" ^D / # chmod +x bin/server.sh / # exit modifying containers dvps.me/docker-ws-cheat
  20. > docker ps --latest > docker diff container_name A /.ash_history

    C /bin A /bin/server.sh # now run 3 containers with server.sh in parallel ... what changed? dvps.me/docker-ws-cheat
  21. container commit > docker commit -a ‘Evgeny Zislis <[email protected]>’ \

    abcde123 haws/webserver 96e632d705113241816462ba9c7e94451384a505613dff64af192daf7bc78efb Hey! What is this? dvps.me/docker-ws-cheat
  22. > docker images > docker search mongodb > docker pull

    mongodb/mongodb:latest > docker run -d mongodb/mongodb using images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE busybox latest a9eb17255234 5 days ago 2.433 MB ubuntu 14.04 99ec81b80c55 4 weeks ago 266 MB dvps.me/docker-ws-cheat
  23. # server.sh #!/bin/sh PATH=/bin:/usr/bin nc -ll -p 80 -e echo

    -e "HTTP/1.1 200 OK\n\nI am very FAST!" # Dockerfile FROM busybox:latest ADD server.sh bin/server.sh ENTRYPOINT bin/server.sh > chmod 0750 server.sh && docker build -t haws/webserver . build an image dvps.me/docker-ws-cheat
  24. tags for images > docker tag webserver_yourname webserver > docker

    login user: haws pass: verysecret mail: [email protected] > docker push haws/webserver_yourname dvps.me/docker-ws-cheat
  25. Dockerfile instructions http://docs.docker.com/reference/builder/ FROM image:tag MAINTAINER Evgeny Zislis <[email protected]> RUN

    command # runs it in /bin/sh -c ‘command’ RUN [ “exec”, “param”, “param” ] CMD command # or CMD [ “exec”, “param”, “param” ] ENTRYPOINT command # or ENTRYPOINT [ “exec”, “param” ] dvps.me/docker-ws-cheat
  26. ENV key value ADD src dst # src is file,

    archive, or url (http://) COPY src dst USER someone WORKDIR somewhere Dockerfile instructions cont.
  27. ✓ commit changed containers ✓ inspect difference made to container

    ✓ searching for community images ✓ docker image pulling and pushing ✓ building images using Dockerfiles ✓ injecting files into images with ADD images : what we learned so far
  28. Build two images that depend on each other, and, have

    six degrees of separation when inspected using : > docker images --tree Challenge - images
  29. # exposing container ports in Dockerfile EXPOSE 22 53/udp 514

    > docker run -P -p 22:2222 ... # linking containers - environment & /etc/hosts > docker run -P --link name:alias ... # non-unionfs mount volumes VOLUME [“/data”] > docker run -v /data:/data/mongodb ... # from host > docker run --volumes-from dbdata ... # from container # mounting external volumes into a container > docker run -ti extras docs.docker.com/reference/commandline/cli/
  30. Thank you! We invite you to join Operations Israel Facebook

    group on on.fb.me/Ops-IL www.devops.co.il