Introduction
For creating a LAMP server for Web development
slides.com/mikebarkas/intro-docker-for-developers
/live
Presentation Overview
Discuss basic Docker concepts including:
Images
Containers
Command line tools
Example building a LAMP stack
Docker Intro
What is Docker?
Docker is a software container platform
"A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings."
- docker.com
What is a container?
Virtual Machine vs Docker
Hardware
Host OS
Hypervisor (vbox or vmware)
Virtual Machine
Guest OS
Application
Packages
Libraries
Guest OS
Application
Packages
Libraries
Hardware
Host OS
Docker Engine
Application
Packages
Libraries
Docker
Application
Packages
Libraries
Images and Containers
Hardware
Host OS
Docker Engine
Application
Packages
Libraries
Docker
Created with Docker image
Docker container
One or more images can be run in a container
Only the processes/programs from the images are available in the container
Docker Images
A Docker image is built from a series of layers
Each command in the Dockerfile creates a read-only layer
The Dockerfile contains commands or file system changes used during runtime.
An image does not have state and it never changes
Dockerfile Example
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y openssh-server
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Image used in container
Read-only layers
Docker may use these for other builds
List Docker Images
- docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mikebarkas/apache24-php70 0.1 fd5cf1167757 3 weeks ago 367 MB
apache24-php56 latest 469164cf53f7 3 weeks ago 369 MB
mikebarkas/apache24-php56 0.1 469164cf53f7 3 weeks ago 369 MB
ubuntu14 latest 9652fdb58ee0 4 weeks ago 688 MB
certbot_development latest 7b8d0133e9e1 4 weeks ago 489 MB
ubuntu 16.04 ebcd9d4fca80 5 weeks ago 118 MB
ubuntu trusty 2ff3b426bbaa 5 weeks ago 188 MB
mariadb 10.1 98f78d96be9c 6 weeks ago 395 MB
ubuntu latest f7b3f317ec73 8 weeks ago 117 MB
wordpress latest dfbefe759772 4 months ago 400 MB
postgres latest 4023a747a01a 5 months ago 265 MB
mysql 5.7 f3694c67abdb 5 months ago 400 MB
phptest 7.0 2def50f66eea 7 months ago 420 MB
mikebarkas/phpunittest 7.0 2def50f66eea 7 months ago 420 MB
mikebarkas/ubuntu14-python3-pip3 0.1 234a4c11fce3 7 months ago 349 MB
python 3.5 302ab18dbdd0 7 months ago 682 MB
drupal 7.51-apache 9f6f9f3c360d 8 months ago 437 MB
php 7.0-cli 95963ad7e7a6 8 months ago 363 MB
ubuntu 14.04 1e0c3dd64ccd 8 months ago 188 MB
Running Docker Containers
Run a Docker image in a container
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run multiple services for an application
docker-compose [COMMAND] [OPTIONS]
Docker Compose
Create multiple services in a container with a compose file
docker-compose.yml
Pull in multiple images to create services
Services will be networked with each other
Specify directories for application code
Define custom settings for the services
Docker Compose Example
version: '3'
services:
db:
image: mariadb:10.1
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: secretpassword
MYSQL_DATABASE: db_name
MYSQL_USER: db_user
MYSQL_PASSWORD: db_password
app:
depends_on:
- db
image: mikebarkas/apache24-php70
ports:
- "8000:80"
environment:
DRUPAL_DB_HOST: db:3306
DRUPAL_DB_USER: username
DRUPAL_DB_PASSWORD: password
docker-compose.yml
Docker Compose Commands
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
Commands:
up Create and start containers
down Stop and remove containers, networks, images, and volumes
start Start services
stop Stop services
ps List containers
rm Remove stopped containers
(many others)
Process Overview
Create custom Docker image with a Dockerfile
Build your custom image with docker build .
Run your new image with docker run [options]
Run multi-container services as a collection for a complete application with docker-compose up
Group multiple images and specific settings with docker-compose.yml
Another Source for Images
In addition to building your custom images
https://hub.docker.com/
Docker Hub
Community repository for Docker images
- docker search node
NAME DESCRIPTION STARS OFFICIAL
node Node.js is a JavaScript-based platform for... 4083 [OK]
nodered/node-red-docker Node-RED Docker images. 61
strongloop/node StrongLoop, Node.js, and tools. 38
kkarczmarczyk/node-yarn Node docker image with yarn package manage... 28
bitnami/node Bitnami Node.js Docker Image 20
siomiz/node-opencv _/node + node-opencv 10
dahlb/alpine-node small node for gitlab ci runner 8
Intro to Docker for Developers
By mikebarkas
Intro to Docker for Developers
Overview of the basic concepts for creating a development LAMP environment using Docker.
- 180