28
Docker for Web Developers: A Sneak Peek MOHD SYUKOR ABDUL NOVEMBER 5, 2016

Docker for Web Developers: A Sneak Peek

  • Upload
    msyukor

  • View
    444

  • Download
    3

Embed Size (px)

Citation preview

Docker for Web Developers: A Sneak PeekMOHD SYUKOR ABDULNOVEMBER 5, 2016

2

What is Docker? Docker is a platform for developing, shipping and running

applications using container virtualization technology.

The Docker Platform consists of multiple products/tools: Docker Engine Docker Registry Docker Machine Docker Swarm Docker Compose Kitematic

Docker for Linux Docker for Mac Docker for Windows Docker for Windows

Server 2016

https://www.docker.com/

3

Why Docker?

Containers running on a single machine share the same operating system kernel; they start instantly and use less RAM. Images are constructed from layered filesystems and share common files, making disk usage and image downloads much more efficient.

LIGHTWEIGHTDocker containers are based on open standards, enabling containers to run on all major Linux distributions and on Microsoft Windows -- and on top of any infrastructure.

OPENContainers isolate applications from one another and the underlying infrastructure, while providing an added layer of protection for the application.

SECURE BY DEFAULT

4

Docker vs Virtual Machine

ContainerVirtual Machine

5

Docker Solution Docker enables developers and IT admins to

build, ship and run any application, anywhere.

6

Docker’s Architecture

7

Example Use Case: Development and Test in the Cloud

DEVELOPERS IT PRO

BUILDDevelopment Environments SHIP

Secure Content & Collaboration

Developers

Version

control DockerTrusted Registry

QA / QE

Staging

8

Docker DataCenter

9

Docker’s Commandsdocker info # displays system wide information of Dockerdocker build # Build an image from a Dockerfiledocker images # List all images on a Docker hostdocker pull # Pull an image from a Registrydocker run # Run an imagedocker ps # List all running and stopped instancesdocker stop # Stop a running instancesdocker rm # Remove an instancedocker rmi # Remove an imagedocker stats # Show running containers‘ resource usage infodocker attach # Attach to a running containerdocker logs # Fetch the logs of a containerdocker inspect # Return low-level information on a container or imagedocker history # Show the history of an image

AND MORE at https://docs.docker.com/engine/reference/commandline/

10

The Secret Recipe 1: Dockerfile Dockerfiles = image

build script.

Simple syntax for building images.

Automate and script the images creation.

Dockerfile:-------------------------------------------------------FROM debian:jessie

ENV HTTPD_PREFIX /usr/local/apache2ENV PATH $HTTPD_PREFIX/bin:$PATHRUN mkdir -p "$HTTPD_PREFIX" \

&& chown www-data:www-data "$HTTPD_PREFIX"WORKDIR $HTTPD_PREFIXRUN apt-get update \

&& apt-get install -y --no-install-recommends \libapr1 \libaprutil1 \libaprutil1-ldap \libapr1-dev \libaprutil1-dev \libpcre++0 \libssl1.0.0 \

&& rm -r /var/lib/apt/lists/*COPY httpd-foreground /usr/local/bin/EXPOSE 80CMD ["httpd-foreground"]-------------------------------------------------------docker build -t my-apache2 .

11

The Secret Recipe 2: Docker Compose Compose is a tool for

defining and running multi-container Docker applications.

The secret recipe is in the docker-compose.yml file.

docker-compose.yml:---------------------------------------------------joomla: image: joomla links: - joomladb:mysql ports: - 8080:80

joomladb: image: mysql:5.6 environment: MYSQL_ROOT_PASSWORD: example---------------------------------------------------

docker-compose up -d

12

Docker for PHP Developers

Dockerfile:------------------------------------------------------------------

FROM php:7.0-apacheCOPY src/ /var/www/html/

------------------------------------------------------------------

docker build -t my-php-app .

docker run -d --name my-running-app my-php-app

13

Docker for Java DevelopersDockerfile:------------------------------------------------------------------------

FROM jboss/wildflyADD your-awesome-app.war

/opt/jboss/wildfly/standalone/deployments/------------------------------------------------------------------------

docker build --tag=wildfly-app .

docker run -it wildfly-app

14

Docker for Python DevelopersDockerfile:-----------------------------------------------------------------------FROM ubuntu:16.04MAINTANER Your Name "[email protected]"RUN apt-get update -y && \ apt-get install -y python-pip python-devCOPY ./requirements.txt /app/requirements.txtWORKDIR /appRUN pip install -r requirements.txtCOPY . /appENTRYPOINT [ "python" ]CMD [ "app.py" ]-----------------------------------------------------------------------

docker build -t myflask1:latest .

docker run -d -p 5000:5000 myflask1

15

Docker for Node.js DevelopersDockerfile:--------------------------------------------------------------------FROM nodeRUN mkdir -p /usr/src/appWORKDIR /usr/src/appCOPY package.json /usr/src/app/RUN npm installCOPY . /usr/src/appEXPOSE 8080CMD [ "npm", "start" ]--------------------------------------------------------------------

docker build -t yourname/node-web-app .

docker run -p 49160:8080 -d yourname/node-web-app

16

Docker for Go Developers$ docker run --rm -it -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.6 bash$ for GOOS in darwin linux; do> for GOARCH in 386 amd64; do> go build -v -o myapp-$GOOS-$GOARCH> done> done

17

Docker for Database Server MySQL Server:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:8

MariaDB Server:docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d

mariadb

Percona Server:docker run --name some-percona -e MYSQL_ROOT_PASSWORD=my-secret-pw -d \ percona:5.7.14

PostgreSQL Server:docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d \ postgres:9.6

MongoDB Server:docker run --name some-mongo -d mongo

18

Docker for WordPress docker run --name wordpressdb -e MYSQL_ROOT_PASSWORD=password \

-e MYSQL_DATABASE=wordpress -d mysql:5.7

docker run -e WORDPRESS_DB_PASSWORD=password -d --name wordpress \--link wordpressdb:mysql wordpress

19

Docker for Joomla docker run --name mysql1 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7 docker run --name joomla1 --link mysql1:mysql -d joomla docker run --name some-joomla --link mysql1:mysql -p 8080:80 -d joomla

docker run -d -p 80:80 -p 3306:3306 webkul/joomla:latest

20

Docker for Drupal

docker run --name some-drupal --link some-mysql:mysql -d drupal

21

Docker for Apache Web Server docker run -dit --name my-apache-app \

-v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4

Dockerfile:------------------------------------------------------------------ FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/------------------------------------------------------------------

docker build -t my-apache2 .

docker run -dit --name my-running-app my-apache2

OR

22

Docker for Nginx Web Server

docker run --name docker-nginx -p 8080:80 -d \-v ~/docker-nginx/html:/usr/share/nginx/html nginx

23

Docker for Caddy Web Server

docker run -d -p 2015:2015 abiosoft/caddy:php

24

Docker for ELK Stack

docker pull sebp/elk docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it \

--name elk sebp/elk

25

Docker for OS??? docker pull ubuntu:16.04

docker run ubuntu:16.04 /bin/bash

docker run –it alpine ash

docker run –it centos bash

docker run –it fedora bash

docker run ubuntu:16.04 grep -v '^#' /etc/apt/sources.list

26

Docker for Microsoft’s Platform???

docker pull microsoft/nanoserver

docker pull microsoft/iis

docker pull microsoft/dotnet

docker pull microsoft/sample-httpd

docker pull microsoft/mssql-server-2016-express-windows

27

Docker Repositories

Official Repositories – https://hub.docker.com/explore/

28

Docker for Web Developers: A Sneak Peek

Q &

A