Date post: | 16-Jul-2015 |
Category: |
Technology |
Upload: | dharmit-shah |
View: | 264 times |
Download: | 0 times |
Who am I?
(Earlier)
@
@
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
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
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
What is a Layer? (contd.)
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
What are Docker images? (contd.)
What are Docker images? (contd.)
Creating a container
$ sudo docker pull ubuntu:14.10
$ sudo docker run -ti ubuntu:14.10 /bin/bash
$ ip a
$ hostname
$ uname -a
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>
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
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
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
If it didn’t work for you
nsenter
➔ Data backup
➔ Check logs
➔ Restart a service
➔ Edit configuration
➔ Debugging
SSH
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
Image and content credits
➔ http://docker.com
➔ http://redhat.com
➔ http://auberginesolutions.com
Questions?