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

Course Agenda

Why Use Docker as a Developer?

Module Agenda

Module Agenda

What Is Docker?

What Is Docker?

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

role image

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 Run

Docker Containers Versus Virtual Machines

Docker Container

Docker Benefits(for Web Developers)

Docker Benefits

(for Web Developers)

Docker Benefit

Accelerate Developer On boarding

accelerate developer

Eliminate App Conflicts

eliminate app Conflicts

Environment Consistency

environment consistency

Ship Software Faster

ship software

Docker Tools

docker tools

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

docker toolbox

Docker in Action

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

module agenda1

Installing Docker Toolbox on Mac

Installing Docker Toolbox on Windows

Getting Started with Docker Kitematic

Docker Kitematic Overview

docker-kitematic

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

Module Agenda2

Docker Toolbox

docker toolbox
  • Docker Client
  • Docker Machine
  • Docker Compose
  • Docker Kitematic
  • VirtualBox

Getting Started with Docker Machine

Docker Machine Overview

Docker Machine

Key Docker MachineCommands

key docker machine
  • 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

docker client

Key Docker Client Commands

key docker client
  • docker pull [image name]
  • docker run [image name]
  • docker images
  • docker ps

Docker Client in Action (Mac)

Docker Chent in Action (Windows)

Docker Commands Review

Key Docker Machine Commands

key docker machine
  • 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

key docker client
  • docker pull [image name]
  • docker images
  • docker rmi [image ID]

Key Docker Client Container Commands

key docker client
  • 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

module agenda3
question

Answer

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.

The Layered File System

Layers (From a Dessert Perspective)

layers

Images, Containers and File Layers

container and file

Containers Can Share Image Layers

containers can share
question1

Containers and Volumes

Docker Volumes

docker valume

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

volume overview

Source Code, Volumes and Containers

Understanding Volumes

understanding values

Creating a Data Volume

creating a data

Locating a Volume

locating a valume

Customizing Volumes

customize valume

Customizing the Host Location for a Data Volume

customizing the host

Locating a Volume

locating a valume1

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:
    • docker run -v
  • 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 agenda4

Module Agenda

question2

Answer

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

Dockerfile Overview

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

key dockerfile

Dockerfile Example

dockerfile exmple

Creating a Custom Node.js Dockerfile

Building a Node.js Image

Building a Custom Image

building a custom

Creating a Custom ASP.NET Core Dockerfile

Buflding an ASP.NET Core Image

Building a Custom Image

building a custom1

Publishing an Image to Docker Hub

Publishing an Image to Docker Hub

publishing an image

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

module-agenda5

Getting Started with Container Linking

The Need for Linked Containers

the need linked

Docker Container Linking Options

docker-container1

Linking Containers by Name (legacy linking)

Steps to Link Containers

step to link

1. Run a Container with a Name

run a container

2. Link to Running Container By Name

link to running

3. Repeat for Additional Containers

link to running

Linking Node.js and MongoDB Containers

Linking ASP.NET Core and PostgreSQL Containers

Getting Started with Container Networks

Understanding Container Networks

understanding-container

Steps to Create a Container Network

step to creat

1. Create a Custom Container Network

creat-a-custom

2. Run Containers in the Container Network

run container

Container Networks in Action

Linking Multiple Containers

Is There an Easier Way?

easier way

Docker Compose Can Simplify Container Linking

docker-compose

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

module-agenda6

Getting Started with Docker Compose

Docker Compose Manages Your Application Lifecycle

docker-compose1

Docker Compose Features

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

need for docker

Docker Compose Workflow

docker compose2

The docker-compose.yml File

The Role of the Docker Compose File

role of the docker

Docker Compose and Services

docker compose service

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
						
					

Docker Compose Commands

Key Docker Compose Commands

key docker compose
  • 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-service

Building Services

building-service1

Building Specific Services

building specific

Starting Services Up

starting services

Creating and Starting Containers

creating and starting

Creating and Starting Containers

creating and starting1

Tearing Down Services

tearing down service

Stop and Remove Containers

stop and remove

Stop and Remove Containers, Images, Volumes

stop and remove1

Docker Compose in Action

Setting up Development Environment Services

Development Environment Services

development-enviroment

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

module-agenda7

Getting Started with Docker Cloud

Deploying Containers to the Cloud

depolying

Docker Cloud Features

docker cloud feature
  • 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

docker cloud workflow

Linking to a Cloud Provider

Deploying a Node

Creating a Stack

Managing Stack Services

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

docker web

Images and Containers

images and container

Docker Toolbox

docker toolbox1

Docker Volumes

docker valimes

Dockerfileand Custom Images

dockerfile and custom.jpg

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

containers and docker

Docker

docker1

questions?

questions

THANKS!!!