Docker for Web Developers
WHY USE DOCKER AS A DEVELOPER?
By scmGalaxy.com
About Me
DevOps@RajeshKumar.XYZ
Placeholder
Promo Video Demo
of Parts of Course Goes Here
I'll talk over the video
Created after the course is done
Course Agenda
Why Use Docker as a Developer?
Module Agenda
What Is Docker?
- Lightweight, open, secure platform
- Simplify building, shipping, running apps
- Shipping container system for code
- Runs natively on Linux or Windows Server
- Runs on Windows or Mac Development
- machines (with a virtual machine)
- Relies on “images” and “containers”
The Role of Images and Containers
Image
A read-only template composed of layered
filesystems used to share common files and
create Docker container instances.
Container
An isolated and secured shipping container
created from an image that can be run,
started, stopped, moved and deleted.
Where Does Docker Run?
Docker Containers Versus Virtual Machines
Docker Benefits(for Web Developers)
Docker Benefits
(for Web Developers)
Accelerate Developer On boarding
Eliminate App Conflicts
Environment Consistency
Ship Software Faster
Docker Toolbox
Provides image and container tools
Virtual Machine (for Windows/Mac)
Works on Windows, Mac, Linux
https://www.docker.com/docker-toolbox
Docker Toolbox Tools
Summary
- Docker simplifies building, shipping and
running apps
- Runs natively on Linux and Windows
Server
- Docker is NOT the same as using Virtual
Machines
- Key benefits to Web Developers:-
- Accelerate developer onboarding
- Simplify working with multiple apps
- Consistency between environments
- Ship faster!
Setting up Your Dev Environment with Docker Toolbox
Module Agenda
Installing Docker Toolbox on Mac
Installing Docker Toolbox on Windows
Getting Started with Docker Kitematic
Docker Kitematic Overview
Summary
Docker Toolbox provides several tools
that help manage images and containers
Docker Toolbox includes VirtualBox for
running Docker on Mac or Windows
Docker Kitematic provides a visual way
to work with images and containers
Using Docker Machine and Docker Client
Module Agenda
Docker Toolbox
- Docker Client
- Docker Machine
- Docker Compose
- Docker Kitematic
- VirtualBox
Getting Started with Docker Machine
Docker Machine Overview
Key Docker MachineCommands
- docker-machine Is
- docker-machine start [machine name]
- docker-machine stop [machine name]
- docker-machine env [machine name)
- docker-machine ip [machine name]
Docker Machine in Action (Mac)
Docker Machine in Action (Windows)
Getting Started with Docker Client
Docker Client Overview
Key Docker Client Commands
- docker pull [image name]
- docker run [image name]
- docker images
- docker ps
Docker Client in Action (Mac)
Docker Chent in Action (Windows)
Key Docker Machine Commands
- docker-machine Is
- docker-machine start [machine name]
- docker-machine stop [machine name]
- docker-machine env [machine name]
- docker-machine ip [machine name]
- docker-machine status [machine name]
Key Docker Client Image Commands
- docker pull [image name]
- docker images
- docker rmi [image ID]
Key Docker Client Container Commands
- docker run [image name]
- docker ps -a
- docker rm [container ID]
Summary
Docker Machine creates and manages machines
Docker Client manages images and containers
Hooking Your Source Code into a Container
Module Agenda
Answer
- 1. Create a container volume that points to
the source code.
- 2. Add your source code into a custom
image that is used to create a container.
Layers (From a Dessert Perspective)
Images, Containers and File Layers
Containers Can Share Image Layers
Docker Volumes
What is a Volume?
- Special type of directory in a container
typically referred to as a “data volume”
- Can be shared and reused among
containers
- Updates to an image won’t affect a data
volume
- Data volumes are persisted even after the
container is deleted
Volume Overview
Source Code, Volumes and Containers
Understanding Volumes
Creating a Data Volume
Locating a Volume
Customizing Volumes
Customizing the Host Location for a Data Volume
Locating a Volume
Hooking a Volume to Node.js Source Code
Hooking a Volume to ASP.NET Source Code
Removing Containers and Volumes
Creating a Docker Managed Volume
docker run -p 8080:3000 nudvar/www node
Docker Controlled Volumes
docker inspect mycontainer
...
“Mounts”: [
{
“Name”: “d185...86459”,
“Source”: “/mnt/.../var/Iib/docker/volumes/d185...86459/ data”,
“Destination”: “/var/www”,
“Driver”: “local”,
“RN”: true
}
]
...
Removing Volumes
docker rm -v lastContainer
summary
- Docker images and containers rely on a
“layered file system”
-
Source Code can be hooked to a container using volumes:
- Volumes are persisted on the Docker Host
-
Volumes can be removed using:
- docker rm -v last Container
Building Custom Images with Dockerfile
Module Agenda
Module Agenda
Answer
- Create a container volume that points to
the source code.
- Add your source code into a custom
image that is used to create a container.
Getting Started with Dockerfile
Dockerfile and Images
Dockerfile Overview
- Text file used to build Docker images
- Contains build instructions
- Instructions create intermediate image that
can be cached to speed up future builds
- Used with “docker build” command
Key Dockerfile Instructions
Dockerfile Example
Creating a Custom Node.js Dockerfile
Building a Custom Image
Creating a Custom ASP.NET Core Dockerfile
Buflding an ASP.NET Core Image
Building a Custom Image
Publishing an Image to Docker Hub
Publishing an Image to Docker Hub
Summary
- Dockerfile is a simple text file with
instructions that is used to create an
image
- Each Dockerfile starts with a FROM
instruction
-
Custom images are built using:
- docker build -t /imageName
- Images can be pushed to Docker Hub
Communicating Between Docker Containers
Module Agenda
Getting Started with Container Linking
The Need for Linked Containers
Docker Container Linking Options
Linking Containers by Name (legacy linking)
Steps to Link Containers
1. Run a Container with a Name
2. Link to Running Container By Name
3. Repeat for Additional Containers
Linking Node.js and MongoDB Containers
Linking ASP.NET Core and PostgreSQL Containers
Getting Started with Container Networks
Understanding Container Networks
Steps to Create a Container Network
1. Create a Custom Container Network
2. Run Containers in the Container Network
Container Networks in Action
Linking Multiple Containers
Is There an Easier Way?
Docker Compose Can Simplify Container Linking
summary
- Docker containers communicate using
link or network functionality
- The --link switch provides “legacy
linking”
- The --net command-line switch can be
used to setup a bridge network
- Docker Compose can be used to link
multiple containers to each other
Managing Containers with Docker Compose
Module Agenda
Getting Started with Docker Compose
Docker Compose Manages Your Application Lifecycle
Docker Compose Features
Manages the whole application lifecycle:
- Start, stop and rebuild services
- View the status of running services
- Stream the log output of running
services
- Run a one-off command on a service
The Need for Docker Compose
Docker Compose Workflow
The docker-compose.yml File
The Role of the Docker Compose File
Docker Compose and Services
Key Service Configuration Options
build |
environment |
image |
networks |
ports |
volumes |
docker-compose.yml Example
version: ‘2’
services:
node:
build:
context:.
dockerfile: node.dockerfile
networks:
-nodeapp-network
mongodb:
Image: mongo
networks:
- nodeapp-network
networks:
nodeapp-network
driver: bridge
Key Docker Compose Commands
- docker-compose build
- docker-compose up
- docker-compose down
- docker-compose logs
- docker-compose ps
- docker-compose stop
- docker-compose start
- docker-compose rm
Building Services
Building Services
Building Specific Services
Starting Services Up
Creating and Starting Containers
Creating and Starting Containers
Tearing Down Services
Stop and Remove Containers
Stop and Remove Containers, Images, Volumes
Setting up Development Environment Services
Development Environment Services
CreaUng a Custom docker-compose.yml File
Managing Development Environment Services
Summary
- Docker Compose simplifies the process of building, starting and stopping services
- docker-compose.ymldefines services
- Excellent way to manage services used in
a development environment
- Key DockerCompose commands include "build", "up" and "down"
Running Your Containers in the Cloud
Module Agenda
Getting Started with Docker Cloud
Deploying Containers to the Cloud
Docker Cloud Features
- Link to Different Cloud Providers
- Setup and provision nodes
- Create a stack of Dockerservices to deploy in the cloud
- Manage stacks and services
DockerCloud Workflow
Linking to a Cloud Provider
Summary
-
Docker Cloud provides a simplified way to migrate a development environment to the cloud
- Relies on a YAML file
- Docker Cloud can:
- Create and provision nodes
- Create stacks that contain services
- Manage stacks and services
Reviewing the Case for Docker
Docker Web Development Benefits
Images and Containers
Docker Toolbox
Docker Volumes
Dockerfileand Custom Images
Docker Compose
version: '2'
services:
node:
build:
context: .
dockerfile: node.dockerfile
networks:
-nodeapp-network
mongodb:
image: mongo
networks:
-nodeapp-network
networks:
nodeapp-network
driver: bridge
Containers and Docker Cloud
Docker
questions?