0% found this document useful (0 votes)
4 views31 pages

HelpSession6

The document provides an introduction to Docker, covering its definition, basic commands, and the architecture of Docker images and containers. It explains the differences between Docker containers and virtual machines, as well as networking concepts and the use of Docker Compose for managing multi-container applications. Additionally, it includes examples of Dockerfiles and commands for building and running applications using Docker.

Uploaded by

venduinopi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views31 pages

HelpSession6

The document provides an introduction to Docker, covering its definition, basic commands, and the architecture of Docker images and containers. It explains the differences between Docker containers and virtual machines, as well as networking concepts and the use of Docker Compose for managing multi-container applications. Additionally, it includes examples of Dockerfiles and commands for building and running applications using Docker.

Uploaded by

venduinopi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Introduction to Docker

CS370
Agenda
Section 1: Section 3:
What is Docker
What is Not Docker Networking
Basic Docker Commands
Dockerfiles

Section 2: Section 4:

Anatomy of a Docker image Docker compose / stacks


Docker volumes Demo
Section 1: What is
Docker
Basic Docker Commands
Dockerfiles
• Li ghtw ei ght, open, secure platform
Si m pl i fy building, shipping, running
W h at Is D o c ke r ? apps

• R u n s natively o n L i n u x or W i n d o w s
Ser ver
• R u n s o n W i n d o w s or Mac
D e v e l o p m e n t m ac hi nes (with a
virtual m ac hi ne)
• Relies o n " i m a g e s " a n d "containers"
What is a container?
•Standardized packaging for
software and dependencies
•Isolate apps from each other
•Share the same OS kernel
•Works for all major Linux
distributions
•Containers native to Windows
Server 2016
The Role of Images and Containers

D o c ke r I m a g e D oc ke r Container

E xa m p l e : Ubuntu with Node.js a n d C re ate d b y u s i n g an i mage. R u n s


Ap p l i cat i o n C o d e your application.
Docker containers are NOT VMs
• Easily misconceptualised
• Fundamentally different architectures

7
Docker Containers Versus Virtual Machines

App 1 App 2

Bins/Libs Bins/Libs

App 1 App 2
Guest O S Guest O S
Bins/Libs Bins/Libs

Hypervisor Docker Engine

Host Operating System Host Operating System

Virtual Machines D o c ke r Containers


Using Docker: Build, Ship, Run Workflow
Developers IT Operations

BUILD SHIP RUN


Development Environments Create & Store Images Deploy, Manage, Scale

9
Some Docker vocabulary
Docker Image
The basis of a Docker container. Represents a full application

Docker Container
The standard unit in which the application service resides and executes

Docker Engine
Creates, ships and runs Docker containers deployable on a physical or
virtual, host locally, in a datacenter or cloud service provider

Registry Service (Docker Hub(Public) or Docker Trusted


Registry(Private))
Cloud or server based storage and distribution service for your images
10
Basic Docker Commands
$ docker image pull node:latest

$ docker image ls
$ docker container run –d –p 5000:5000 –-name node node:latest

$ docker container ps

$ docker container stop node(or <container id>)

$ docker container rm node (or <container id>)

$ docker image rmi (or <image id>)

$ docker build –t node:2.0 .

$ docker image push node:2.0

$ docker --help
Docker Build Cache Gotcha
• Sometimes you will change your Dockerfile and do a build and yet your
container image will not change.
• This is because of the docker cache – when you do a docker build it trys to
intelligently cache the layers such that it only rebuilds the minimum number
of layers.
• You can override this behavior by doing:
• docker build –t <image-name> . --no-cache
• You can also avoid this by deleting the container image and then rebuilding
it, but it is likely more convenient for you to use the no-cache option in
docker build shown above.

• Sometimes you may also need to delete the image and completely regenerate.
• You can remove all unused images with docker image prune -a
Docker Build Args Gotcha
• You can pass build
Dockerfile – Linux Example
• Instructions on how to build
a Docker image

• Looks very similar to


“native” commands
• Important to optimize
your Dockerfile

•Dockerizing a Node.js web app

14
Section 2:
Anatomy of a Docker
Let’s Go Back to Our Dockerfile

16
Each Dockerfile Command Creates a Layer


EXPOSE

COPY

WORKDIR

RUN

FROM

Kernel

17
Docker Image Pull: Pulls Layers

18
Section 3:
Networking
What is Docker Bridge Networking
Docker host Docker host

Cntnr 1 Cntnr 2 Cntnr 3 Cntnr 4 Cntnr 5 Cntnr 6 Cntnr 7

bridgenet1 bridgenet2 bridgenet3

docker network create -d bridge --name bridgenet1

20
Docker Bridge Networking and Port Mapping

Docker host 1
Host port Container port
Cntnr1

10.0.0.8 :80
$ docker container run -p 8080:80 ...

Bridge

172.14.3.55 :8080

L2/L3 physical network

21
Section 4:
Docker Compose
Docker Compose: Multi Container Applications

• Build and run one container at a time • Define multi container app in compose.yml file
• Manually connect containers together • Single command to deploy entire app
• Must be careful with dependencies and start
• Handles container dependencies
up order • Works with Docker Swarm, Networking,
Volumes, Universal Control Plane

49
Docker Compose: Multi Container Applications

version: '2' # specify docker-compose version

# Define the services/containers to be run


services:
angular: # name of the first service
build: client # specify the directory of the Dockerfile
ports:
- "4200:4200" # specify port forwarding

express: #name of the second service


build: api # specify the directory of the Dockerfile
ports:
- "3977:3977" #specify ports forwarding

database: # name of the third service


image: mongo # specify image to build container from
ports:
- "27017:27017" # specify port forwarding
Docker Compose Networking
• By default, docker compose will put all of the services specified in your
compose.yml file will be put on a docker network together.
• This allows you to access the other containers in the network via their name in
the compose.yml file.
• If you have one service named server and another service named database
• Suppose database exposes port 5001 to access the database
• In the server container you can use database:5001 to access it across the
network
• Helpful Tip: The server container may take some time to

25
Docker Compose Networking
• By default, docker compose will put all of the services specified in your
compose.yml file will be put on a docker network together.
• This allows you to access the other containers in the network via their name in
the compose.yml file.
• If you have one service named server and another service named database
• Suppose database exposes port 5001 to access the database
• In the server container you can use database:5001 to access it across the
network

26
Docker Compose: Scale Container
Applications
Python Server
To run Python server-side code, you'll need to use a Python web framework.
Section 1: Section 3:
Flask is a
What is Docker
good lightweight web framework.
What is Not Docker Networking
To run this you'll need to install Python/PIP, then install Flask using pip3 install
Basic Docker Commands
flask. (This should
Dockerfiles be done using the Requirements.txt and docker file)

At this point you should be able to run the Python Flask examples using for
example python3 python-example.py, then navigating to localhost:5000 in
your browser.
Section 2: Section 4:

Anatomy of a Docker image Docker compose / stacks


Docker volumes Demo
Python Flask Server Example
To run Python server-side code, you'll need to use a Python web framework.
Section 1: Section 3:
Flask is a
What is Docker
good lightweight web framework.
What is Not Docker Networking
To run this you'll need to install Python/PIP, then install Flask using pip3 install
Basic Docker Commands
flask. (This should
Dockerfiles be done using the Requirements.txt and docker file)

At this point you should be able to run the Python Flask examples using for
example python3 python-example.py, then navigating to localhost:5000 in
your browser.
Section 2: Section 4:

Anatomy of a Docker image Docker compose / stacks


Docker volumes Demo
Python Client
To run Python Client-side code, you'll need to use requests framework.
Section 1: Section 3:
This is included
What is Docker
by importing the urllib.req
What is Not Docker Networking
Then you need to listen the port you have exposed from the server
Basic Docker Commands
Dockerfiles
Read the content from the port, print the values and close the connection.

Section 2: Section 4:

Anatomy of a Docker image Docker compose / stacks


Docker volumes Demo

You might also like