Docker for Developers

Who am I

Started a CS degree

dropped out because I hated programming

Became a Systems Administrator

The problem

For each project / client

We need our own version of the backend

Node.js v 4.5.0

Node.js v 6.5.0

Node.js v 0.10.0

<--- Teammate A

<--- Teammate B

Teammate C --->

What do we need?

Like a VM but...

Reusable 

Shareable  

Easy

Fast

Small

Isolated

Pure

Functional Programming for devops

Setting up a Node.js environment with Docker

Prerequisites

Install docker

Internet connection (for installing images)

Commands

docker pull

docker run (with some options)

Developer environment for Node.js

> $ docker run -i -t --name node_hello_world -p 3000:3000 -v $(pwd):/data node:6.5.0 /bin/bash                                                                                                                            ⬡ 6.5.0 [±master ●]
Unable to find image 'node:6.5.0' locally
6.5.0: Pulling from library/node

8ad8b3f87b37: Pull complete 
751fe39c4d34: Pull complete 
ae3b77eefc06: Pull complete 
7783aac582ec: Pull complete 
393ad8a32e58: Pull complete 
2d923dade19b: Pull complete 
Digest: sha256:9cd81e673bde91e503fd5022df5d5ff716b4e518718b2196947b62e7340d7e27
Status: Downloaded newer image for node:6.5.0
root@4f977ceb9ade:/# cd /data
root@4f977ceb9ade:/data# npm start
npm info it worked if it ends with ok
npm info using npm@3.10.3
npm info using node@v6.5.0
npm info lifecycle hello_world_node@0.0.0~prestart: hello_world_node@0.0.0
npm info lifecycle hello_world_node@0.0.0~start: hello_world_node@0.0.0

> hello_world_node@0.0.0 start /data
> node ./bin/www

Let's automate it!

We need to create a Dockerfile

FROM node:6.5.0
MAINTAINER Brooks Patton
RUN npm install -g express-generator
CMD /bin/bash
EXPOSE 3000
VOLUME /data
WORKDIR /data

docker build -t brookzerker/node_hello_world .

> $ docker images                                                                                                                                                                                                         ⬡ 6.5.0 [±master ●]
REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
brookzerker/node_hello_world   latest              57d9fe9377e1        3 minutes ago       653.2 MB

So you want a database?

Creating a DB container

> $ docker run --name mongodb -d mongo:3.2.9                                                                                                                                                            ⬡ 6.5.0 [±master ●]
Unable to find image 'mongo:3.2.9' locally
3.2.9: Pulling from library/mongo
Digest: sha256:8ff7bd4acdb123e3922a7fae7f73efa35fba35af33fad0de946ea31370a23cc4
Status: Downloaded newer image for mongo:3.2.9
dec82a473b8f4819d8930a1090c4df36581adcf8310d1c7d65b657580d52f56e

> $ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                      NAMES
dec82a473b8f        mongo:3.2.9         "/entrypoint.sh mongo"   About a minute ago   Up About a minute   0.0.0.0:32769->27017/tcp   mongodb

Lets create a network

Docker custom network

Node.js

MongoDB

docker network create demo

Add the containers to the network

docker network connect demo mongodb

docker network connect demo node_hello_world

root@a60f54dd82a4:/data# ping mongodb
PING mongodb (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: icmp_seq=0 ttl=64 time=0.097 ms
64 bytes from 172.18.0.3: icmp_seq=1 ttl=64 time=0.129 ms
^C--- mongodb ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.097/0.113/0.129/0.000 ms
root@a60f54dd82a4:/data# 

Shell script to set up the project

shell script to set up hello world project

Copy of Developing with Docker

By Miroslav Kubásek

Copy of Developing with Docker

This slide deck is for web developers who wish to be introduced to Docker and how it can help them with their future developing.

  • 1,026