Larry cai <larry.caiyu@gmail.com>
Agenda
 Introduction
 Exercise 1: First docker container
 Exercise 2:Add package and create own docker image
 Exercise...
Environment Preparation
 Boot2docker Installer (127M)
 Contains latest docker already, fast
 Container persistence via ...
Or Ustack online environment
 Register in
https://www.ustack.com/cloudservice/public-cloud/
 Select CoreOsVirtualMachine...
Or Ubuntu 14.04 Environment
 Ubuntu 14.04 (recommend to use virtualbox if windows)
 $ sudo apt-get install docker.io
 $...
Introduction
 Docker is an open-source engine that automates the
deployment of any application as a lightweight, portable...
Exercise 1: First docker container
 Download from central place for ubuntu
 Execute command inside container
 Interacti...
`docker` - the command line tool
 Some common commands:
 $ docker search # search hub.docker.com for an image
 $ docker...
Exercise 2: Add own package and image
 Try to install apache2 inside
 $ docker run -i -t ubuntu /bin/bash
 # sed -i 's/...
Docker image & layer
 Docker images are saved in layered !!
 Differed binary for apache2 image
 $ docker images –tree
W...
Docker image & layer
 When Docker mounts the rootfs, it
starts read-only, it takes advantage of
a union mount (aufs) to a...
Exercise 3: Understand the layer
 Data are stored under /var/lib/docker (root permission)
 aufs is used in boot2docker, ...
Docker service
 Network in container is not visible outside (using NAT)
 The service is exposed by Port !!
 Run –p host...
Docker service
 Interactive mode vs. Daemon (Deattach) mode
(docker run)
-d : run in daemon mode
-i : run in interactive ...
Exercise 4: Expose the service
 Export the port to host as 25890 and start the service
manually
 $ docker run -p 25890:8...
Port forward to Windows
 Use boot2dockerVM IP to
access
 $ boot2docker ip
 http://192.168.59.104:25890
 UseVirtualbox ...
Dockerfile
 Dockerfile instructs on how to build the image
automatically
 Dockerfile Syntax (INSTRUCTION arguments)
 FR...
Exercise 5: Dockerfile apache2/wget
 Write the Dockerfile
$ vi /tmp/Dockerfile
$ cd /tmp
$ docker build –t wget .
$ docke...
Share images in docker repository
 Docker is also a tool for sharing.A repository is a
shareable collection of tagged ima...
(Bonus) Exercise 6: Share your image
 Register in https://hub.docker.com/
 Connect it with your github and build
Learn d...
Bonus: more for docker
 Try run https://github.com/tobegit3hub/seagull to check
your local images/containers
 Run contai...
Summary
 This is getting started training slides, door is open to you.
 Benefit and use case will be added with your gro...
Reference
 https://www.docker.io
 http://prezi.com/d2vm7h0mmze5/containerize-it/
 Blog:
http://blog.thoward37.me/articl...
Books
 http://www.dockerbook.com/The Docker Book
 http://www.manning.com/nickoloff/ Docker in Action
 http://yeasy.gitb...
ChangeLog
 2014/12/31: docker exec instead of attach, MacOS,Add
books
Learn docker in 90 minutes25 04/09/15
Issues
 Boot2docker is excellent to start with, But
 Boot2docker 1.1.0 windows has problem, see issue
https://github.com...
Upcoming SlideShare
Loading in...5
×

Learn docker in 90 minutes

9,239

Published on

Learn docker (http://docker.io) in 90 minutes by several hands exercise

Published in: Technology
0 Comments
48 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
9,239
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
453
Comments
0
Likes
48
Embeds 0
No embeds

No notes for slide

Learn docker in 90 minutes

  1. 1. Larry cai <larry.caiyu@gmail.com>
  2. 2. Agenda  Introduction  Exercise 1: First docker container  Exercise 2:Add package and create own docker image  Exercise 3: Understand layer  Exercise 4: Expose the service  Exercise 5: Dockerfile to build  Exercise 6: Publish your image in docker.io index registry  Reference Learn docker in 90 minutes2 04/09/15 Online for ex1/ex2: https://www.docker.io/gettingstarted/ Online for ex5: https://www.docker.io/learn/dockerfile/
  3. 3. Environment Preparation  Boot2docker Installer (127M)  Contains latest docker already, fast  Container persistence via disk automount on /var/lib/docker  Add proxy /var/lib/boot2docker/profile if needed  $ sudo vi /var/lib/boot2docker/profile  export http_proxy=<your proxy>  export no_proxy=“.company.com”  $ sudo /etc/init.d/docker restart  $ docker -v  User/Passwd: docker/tcuser Learn docker in 90 minutes3 04/09/15 http://boot2docker.io/
  4. 4. Or Ustack online environment  Register in https://www.ustack.com/cloudservice/public-cloud/  Select CoreOsVirtualMachine with key pair  Arrange Public IP for it to access  $ ssh -i id_rsa core@42.64.x.x Learn docker in 90 minutes4 04/09/15 Reference: https://www.ustack.com/blog/running-coreos-on-uos/ (Chinese)
  5. 5. Or Ubuntu 14.04 Environment  Ubuntu 14.04 (recommend to use virtualbox if windows)  $ sudo apt-get install docker.io  $ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker  $ sudo usermod -a -G docker <user>  # <user> is the normal user name  if need proxy  $ sudo vi /etc/default/docker.io  $ sudo service docker.io restart  $ docker -v  Docker version 0.9.1, build 3600720 Learn docker in 90 minutes5 04/09/15 Upgrade to latest docker: http://askubuntu.com/questions/472412/how-do-i-upgrade-docker
  6. 6. Introduction  Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere. Learn docker in 90 minutes6 04/09/15  Based on LXC (Linux Container), easy to use.  Similar to VM as end- user with different features
  7. 7. Exercise 1: First docker container  Download from central place for ubuntu  Execute command inside container  Interactive with container  $ docker search ubuntu # from lots of release  $ docker pull ubuntu:latest # may take minutes Pulling repository ubuntu ad892dd21d60: Pulling dependent layers 511136ea3c5a: Pulling fs layer  $ docker images # list local images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest ad892dd21d60 6 days ago 275.5 MB  $ docker run ubuntu echo “Hello World”  $ docker run -i -t ubuntu bash Learn docker in 90 minutes7 04/09/15
  8. 8. `docker` - the command line tool  Some common commands:  $ docker search # search hub.docker.com for an image  $ docker pull # download image  $ docker images # list all existing local images  $ docker run # initiates a container from an image  $ docker ps # list running containers  $ docker build # build images from Dockerfile  $ docker start/stop/kill # commands  $ docker rm/rmi to remove a container or image Learn docker in 90 minutes8 04/09/15 http://superuser.com/questions/756999/whats-the-difference-between-docker-stop-and-docker-kill
  9. 9. Exercise 2: Add own package and image  Try to install apache2 inside  $ docker run -i -t ubuntu /bin/bash  # sed -i 's/us.archive.ubuntu.com/mirrors.163.com/' /etc/apt/sources.list  # apt-get update && apt-get install –y apache2  # exit  $ docker ps –l # -l means –latest CONTAINER ID IMAGE COMMAND CREATED STATUS c4bd63cc87f1 ubuntu:latest bash 2 minutes ago Exited 2 sec  $ docker commit <container id> apache2 66db661d9ad8681b082bb62b21b6ef5f2ddb4799e3df5dbd8fb23aed16616b1d  Check and run it again to see the apache is there  $ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE apache2 latest 66db661d9ad8 28 seconds ago 298.5 MB ubuntu latest ad892dd21d60 6 days ago 275.5 MB  $ docker run –i –t apache2 bash # check apache Learn docker in 90 minutes9 04/09/15 Slow connection, then use mirror ubuntu
  10. 10. Docker image & layer  Docker images are saved in layered !!  Differed binary for apache2 image  $ docker images –tree Warning: '--tree' is deprecated, it will be removed soon. See usage. └─511136ea3c5aVirtual Size: 0 B └─e465fff03bceVirtual Size: 192.5 MB └─23f361102faeVirtual Size: 192.7 MB └─9db365ecbcbbVirtual Size: 192.7 MB └─ad892dd21d60Virtual Size: 275.5 MBTags: ubuntu:latest └─66db661d9ad8Virtual Size: 298.5 MBTags: apache2:latest Learn docker in 90 minutes10 04/09/15 http://docs.docker.io/terms/layer/
  11. 11. Docker image & layer  When Docker mounts the rootfs, it starts read-only, it takes advantage of a union mount (aufs) to add a read- write file system over the read-only file system.  There may be multiple read-only file systems stacked on top of each other.We think of each one of these file systems as a layer. Learn docker in 90 minutes11 04/09/15 http://docs.docker.io/terms/layer/
  12. 12. Exercise 3: Understand the layer  Data are stored under /var/lib/docker (root permission)  aufs is used in boot2docker, could be others like devicemapper/btrfs …  $ ls –al /var/lib/docker $ ls -1 /var/lib/docker/aufs/diff/ .. 66db661d9ad8681b082bb62b21b6ef5f2ddb4799e3df5dbd8fb23aed16616b1d/ 9db365ecbcbbb20e063eac70842c53e27fcad0e213f9d4ddb78152339cedd3b1/  See what is diff inside /var/lib/docker/aufs/diff/<image id> !!  $ find /var/lib/docker/aufs/diff/66* | grep apache2 Learn docker in 90 minutes12 04/09/15 See more http://blog.thoward37.me/articles/where-are-docker-images-stored/ boot2docker ssh On MacOS, type command below to docker server
  13. 13. Docker service  Network in container is not visible outside (using NAT)  The service is exposed by Port !!  Run –p host:guest # assign port to host  $ docker run –p 25890:80 –i –t apache2 bash  # apache2ctl start Learn docker in 90 minutes13 04/09/15 source from : http://pierre-jean.baraud.fr/blog/2014/06/02/host-docker-containers/
  14. 14. Docker service  Interactive mode vs. Daemon (Deattach) mode (docker run) -d : run in daemon mode -i : run in interactive mode (CTRL-P-Q to quit from shell to enter daemon mode, exit will stop the container) $ docker attach <container ID> : connect to existing container  Other parameters for docker run --name : define container name  Enter into existing docker container (since 1.3 version) $ docker exec -it <container ID> bash Learn docker in 90 minutes14 04/09/15
  15. 15. Exercise 4: Expose the service  Export the port to host as 25890 and start the service manually  $ docker run -p 25890:80 –i -t apache2 bash  root@35ac981a49e5:/# service apache2 start  $ docker ps # in another shell CONTAINER ID IMAGE …. STATUS PORTS NAMES e020aa2c02a5 apache2:latest ….. Up 14 seconds 0.0.0.0:25890->80/tcp web  $ curl http://localhost:25890 # or use 192.168.59.13 to replace localhost  Come into the container again to check  $ docker exec –it e020aa2c02a5 bash  Run contain in daemon mode  $ docker run –p 25891:80 –d –t apache2 apache2ctl –D FOREGROUND Learn docker in 90 minutes15 04/09/15
  16. 16. Port forward to Windows  Use boot2dockerVM IP to access  $ boot2docker ip  http://192.168.59.104:25890  UseVirtualbox (may cause network issues, not recommend)  25890 is visible inVM  8080 is visible in Host (Windows)  http://localhost:8080 Learn docker in 90 minutes16 04/09/15
  17. 17. Dockerfile  Dockerfile instructs on how to build the image automatically  Dockerfile Syntax (INSTRUCTION arguments)  FROM – defines base image  RUN - executes arbitrary command ENV – sets environment  EXPOSE – expose a port  ADD – add local file  CMD – default command to execute  MAINTAINER – author information  Used by docker build Learn docker in 90 minutes17 04/09/15
  18. 18. Exercise 5: Dockerfile apache2/wget  Write the Dockerfile $ vi /tmp/Dockerfile $ cd /tmp $ docker build –t wget . $ docker images --tree  (may need ENV http_proxy <proxy>)  Start the wget image and verify !! Learn docker in 90 minutes18 04/09/15
  19. 19. Share images in docker repository  Docker is also a tool for sharing.A repository is a shareable collection of tagged images that together create the file systems for containers.  Public repo. <username>/<repo_name>  Trusted image  $ docker search/pull/login/push Learn docker in 90 minutes19 04/09/15 http://docs.docker.com/docker-hub/repos/
  20. 20. (Bonus) Exercise 6: Share your image  Register in https://hub.docker.com/  Connect it with your github and build Learn docker in 90 minutes20 04/09/15
  21. 21. Bonus: more for docker  Try run https://github.com/tobegit3hub/seagull to check your local images/containers  Run container in daemon  Several docker container as a complete service  Share disk between containers  Share disks with host  Network …  See next CodingWithMe for “Build Service With Docker” http://www.slideshare.net/larrycai/build-service-withdockerin90mins Learn docker in 90 minutes21 04/09/15
  22. 22. Summary  This is getting started training slides, door is open to you.  Benefit and use case will be added with your growing competence  Docker grows very fast, follow it.  Docker vs. openstack ? Friends/Competition … Learn docker in 90 minutes22 04/09/15
  23. 23. Reference  https://www.docker.io  http://prezi.com/d2vm7h0mmze5/containerize-it/  Blog: http://blog.thoward37.me/articles/where-are-docker-images-stored/  http://stackoverflow.com/questions/17252356/run-a-service-automatically-in-a-docker-container  Cool service  http://drone.io http://travis-ci.org open source CI system  https://quay.io another register service  http://www.tutum.co/ PaaS,AWS+Heroku  http://ustack.com coreos image provider  http://docker.cn http://dockerpool.com/ sChinese docker service Learn docker in 90 minutes23 04/09/15
  24. 24. Books  http://www.dockerbook.com/The Docker Book  http://www.manning.com/nickoloff/ Docker in Action  http://yeasy.gitbooks.io/docker_practice/ Docker 从入 到 践门 实 Learn docker in 90 minutes24 04/09/15
  25. 25. ChangeLog  2014/12/31: docker exec instead of attach, MacOS,Add books Learn docker in 90 minutes25 04/09/15
  26. 26. Issues  Boot2docker is excellent to start with, But  Boot2docker 1.1.0 windows has problem, see issue https://github.com/boot2docker/windows-installer/issues/23 (choose other distribution or check inside)  Inside container, DNS could be set to google default, see issue https://github.com/boot2docker/boot2docker/issues/357 Workaround (welcome PR) $ sudo udhcpc $ sudo /etc/init.d/docker restart  Share folder using guest addition (not officially used, but popular) https://medium.com/boot2docker-lightweight-linux-for- docker/boot2docker-together-with-virtualbox-guest-additions- da1e3ab2465c Learn docker in 90 minutes26 04/09/15
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×