Download - Docker hands-on
![Page 2: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/2.jpg)
Who am I?
(Earlier)
@
@
![Page 3: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/3.jpg)
Agenda
Talk
➔ Understanding the Docker terminology➔ What is a layer?➔ What are Docker images?
Hands-on
➔ Creating a container➔ Creating a docker image➔ Dockerfile➔ Using nsenter
![Page 4: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/4.jpg)
What is a Layer?
➔ In traditional Linux, kernel mounts the root file system as read-only and later
switches to read-write mode
➔ When Docker mounts the root, it starts read-only
➔ Later, instead of turning to read-write mode, it adds read-write file system over
the read-only file system
➔ There could be multiple read-only file systems stacked on top of each other
➔ Each of this file system is called as layer
![Page 5: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/5.jpg)
What is a layer (contd..)
➔ Any time a process creates a file, this happens in top layer.
➔ If some file from lower layer needs to be updated, it first gets copied to top layer.
➔ Changes go into the copy
➔ Version of file on lower layer remains unchanged but cannot be seen by
applications
➔ Union File System - union of read-write and all read-only layers
![Page 6: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/6.jpg)
What is a Layer? (contd.)
![Page 7: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/7.jpg)
What are Docker images?
➔ In Docker, a read-only layer is called in Image
➔ An image never changes
➔ Each image depends on one more image which forms the layer beneath it
➔ This lower image is sometimes referred to as Parent Image
➔ An image that has no parent image is called Base Image
![Page 8: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/8.jpg)
What are Docker images? (contd.)
![Page 9: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/9.jpg)
What are Docker images? (contd.)
![Page 10: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/10.jpg)
Creating a container
$ sudo docker pull ubuntu:14.10
$ sudo docker run -ti ubuntu:14.10 /bin/bash
$ ip a
$ hostname
$ uname -a
![Page 11: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/11.jpg)
Creating an image
➔ We will create a minimal image from the container we created in previous step
$ sudo docker ps
$ sudo docker ps -a
$ man docker-commit
$ sudo docker commit <container-id> -t <repository>/<tag>
$ sudo docker tag <image> <tag>
![Page 12: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/12.jpg)
What is a Dockerfile?
➔ Automates building images
➔ A text document that contains commands to build an image
➔ Parsed by command docker build to start image creation process
➔ Clone below repo:
$ git clone https://github.com/dharmit/docker_ahmedabad_meetup_2/
➔ Examine the Dockerfile
![Page 13: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/13.jpg)
What is a Dockerfile? (contd..)
➔ FROM python:3.4
➔ WORKDIR /code
➔ ADD django_code /code
➔ RUN pip3 install -r requirements.txt
➔ CMD python3 manage.py runserver 0.0.0.0:8000
![Page 14: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/14.jpg)
Let’s build!
➔ $ sudo docker build -t docker_ahmedabad .
➔ $ sudo docker images
➔ $ sudo docker run -d -p 80:8000 docker_ahmedabad
➔ $ sudo docker ps
➔ In the browser, navigate to 127.0.0.1
![Page 15: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/15.jpg)
If it didn’t work for you
![Page 16: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/16.jpg)
nsenter
➔ Data backup
➔ Check logs
➔ Restart a service
➔ Edit configuration
➔ Debugging
SSH
![Page 17: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/17.jpg)
nsenter (contd..)
➔ Provided by your distro’s util-linux package
➔ How to use it:
$ PID=$(sudo docker inspect --format {{.State.Pid}}
<container_name_or_ID>)
$ nsenter --target $PID --mount --uts --ipc --net --pid /bin/bash
➔ Specify /bin/bash if you’re using a different shell
![Page 18: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/18.jpg)
Image and content credits
➔ http://docker.com
➔ http://redhat.com
➔ http://auberginesolutions.com
![Page 19: Docker hands-on](https://reader034.vdocument.in/reader034/viewer/2022042522/55a7a1451a28ab2b438b482a/html5/thumbnails/19.jpg)
Questions?