docker: from zero to hero

12
INTRODUCTION

Upload: espeo-software

Post on 21-Mar-2017

749 views

Category:

Technology


17 download

TRANSCRIPT

INTRODUCTION

INTRODUCTION

PROMISES

▸ isolation

▸ lightness

▸ repeatability

▸ speed

▸ easy collaboration

▸ easy configuration

INTRODUCTION

WHY DOCKER?

INTRODUCTION

TECHNOLOGIES

▸ LXC - Linux Containers - process isolation

▸ UnionFS - layered file system

▸ Go - programming language

LINUX

UNION FS LXC

DOCKER (GO)

▸ container - run

▸ image - build

▸ registry - pull/push

INTRODUCTION

TERMS AND OPERATIONS

EXAMPLE

MINECRAFT SERVER# Minecraft 1.8.7 Dockerfile - Example with notes

# Use the offical Debian Docker image with a specified version tag, Wheezy, so not all# versions of Debian images are downloaded.FROM debian:wheezy

# Use APT (Advanced Packaging Tool) built in the Linux distro to download Java, a dependency to run Minecraft.RUN apt-get -y updateRUN apt-get -y install openjdk-7-jre-headless wget

# Download Minecraft Server componentsRUN wget -q https://s3.amazonaws.com/Minecraft.Download/versions/1.9.2/minecraft_server.1.9.2.jar

# Sets working directory for the CMD instruction (also works for RUN, ENTRYPOINT commands)# Create mount point, and mark it as holding externally mounted volumeWORKDIR /dataVOLUME /data

# Expose the container's network port: 25565 during runtime.EXPOSE 25565

#Automatically accept Minecraft EULA, and start Minecraft serverCMD echo eula=true > /data/eula.txt && java -jar /minecraft_server.1.9.2.jar

DEMOJUMP AT THE DEEP END

DEMO

WHAT’S THE GOAL

▸ bpasik’s Node.js app with Mongo DB running on Dockerhttps://github.com/Gustu/Node-Asynchronous-Examples

TOOLS REFERENCE

▸ Docker hubhttps://hub.docker.com/_/nodehttps://hub.docker.com/_/mongo/

▸ Dockerfilehttps://docs.docker.com/engine/reference/builder/

▸ Docker composehttps://docs.docker.com/compose/

DEMO

BUILD IT# DockerfileFROM node:onbuildEXPOSE 3000

RUN IT# run mongo as daemon container and expose it’s 27017 port to localhost’s 27017# WARNING: on Windows or OS X Docker is not running on localhost# it’s running on boot2docker VM with it’s own IP# so it’s exposing this port as e.g. 192.169.99.100:27017# (this also means you’d have to embed this IP into config/default.json)$ docker run -d -p 27017:27017 mongo<< mongo container id here>>

# build our app Docker image and tag it as node-app$ docker build -t node-app .<< lots of logs here >>

# run mongo as daemon and expose container’s port 3000 to localhost’s 3000$ docker run -d -p 3000:3000 node-app<< node-app container id here>>

# you can now access localhost:3000 and see the running containers$ docker ps

DEMO

BUT RUNNING IT BY HAND EACH TIME IS UNCOOL…

# WARNING: remove all containers (running and stopped)$ docker ps -qa | xargs docker rm -f

Cleanup

Declarative docker compose configuration# docker-compose.ymlversion: '2'services: web:

# use our Dockerfile build: .

# expose the port 3000 ports: - "3000:3000" links:

# link the mongo container under hostname 'mongo'# remember to change config/default.json to use mongo:27017

- mongo mongo: image: mongo

$ docker-compose up# try changing public/index.html and refresh the page

Run it!

DEMO

WHAT IF WE WANT TO EDIT LIVE FILES?

$ docker-compose down

Cleanup (the docker-compose way)

Change our Dockerfile to use other base image

# DockerfileFROM nodeEXPOSE 3000

# point to our volume (where the app is mounted)WORKDIR /app

# start with the app’s start commandCMD [ "npm", "start" ]

$ docker-compose up# try changing public/index.html again and see the changes live

Run it!

Change our docker-compose.yml to use a volume

version: '2'services: web: build: . ports: - "3000:3000"

# mount . directory to container’s /app volumes: - .:/app links: - mongo mongo: image: mongo

DEMO

SUMMING UP

▸ we’ve started from running containers by hand

▸ defined Docker compose config with linked containers

▸ changed the app embedded in the image to be mounted as a volume

▸ Dockerization available in my fork of the app:https://github.com/tcichowicz/Node-Asynchronous-Examples