+ All Categories
Home > Technology > Docker hands-on

Docker hands-on

Date post: 16-Jul-2015
Category:
Upload: dharmit-shah
View: 264 times
Download: 0 times
Share this document with a friend
19
Docker Hands-On Dharmit Shah @dharm1t
Transcript
Page 1: Docker hands-on

Docker Hands-On

Dharmit Shah@dharm1t

Page 2: Docker hands-on

Who am I?

(Earlier)

@

@

Page 3: Docker hands-on

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

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

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

What is a Layer? (contd.)

Page 7: Docker hands-on

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

What are Docker images? (contd.)

Page 9: Docker hands-on

What are Docker images? (contd.)

Page 10: Docker hands-on

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

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

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

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

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

If it didn’t work for you

Page 16: Docker hands-on

nsenter

➔ Data backup

➔ Check logs

➔ Restart a service

➔ Edit configuration

➔ Debugging

SSH

Page 17: Docker hands-on

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

Image and content credits

➔ http://docker.com

➔ http://redhat.com

➔ http://auberginesolutions.com

Page 19: Docker hands-on

Questions?


Recommended