Docker

A step before Willy Wonka of Containers

João Daniel

A paradigm called

It Works On My Machine

  • team development
    • no one else develops alone
    • diversity of environments
  • deployment

The end of

It Works On My Machine

  • pack it up!

 

 

  • virtual machines: an alternative
  • containers: the alternative

software

environment

&

Containers x VMs

Docker 101 - Running

<sudo> gpasswd -a $(id -un) docker
docker container run -it node

This will simply add <your-user> to the docker group, which has permission to access the docker service

Now you're running a Node shell inside a container

docker container ls

Empty list of containers... What happened to our Node container?!

docker container ls -a

Now you see it!

Docker 101 - Running

docker container start -i <container-identification>

Let's run our old container again! But wait... what was that name?

docker container rm <container-identification>

Bye-bye, container!

Docker 101 - Running

docker container run -it --name mynode node

How pleasant is to name our stuff

docker container rm mynode

Bye-bye, mynode

Docker 101 - Running

Docker 102 - Creating

  • perfect fit
  • PLAY button

Learn to crawl before you learn to walk

const koa = require('koa'),
      app = new koa(),
      port = process.env.PORT || 8888;

app.use(async ctx => {
    ctx.body = "Hello, world!";
});

app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});

This is our simple app

Docker 102 - Creating

FROM node:9.11.2-alpine

ENV APP_PATH=/usr/src/myapp \
    PORT=8888

WORKDIR $APP_PATH

RUN yarn add koa

COPY app.js ./

EXPOSE $PORT

CMD node app.js

our shipyard

system-level dependencies

pack our work

a port to anchor and ship messages

mkdir -p and cd

default command

One recipe, many cakes

Docker 102 - Creating

environment variable setup

$ docker image build . -t my_app_image

Sending build context to Docker daemon  3.072kB
Step 1/7 : FROM node:9.11.2-alpine
 ---> a56170f59699
Step 2/7 : ENV APP_PATH=/usr/src/myapp     PORT=8888
 ---> Running in 28d44e107a43
Removing intermediate container 28d44e107a43
 ---> 69242f8b73d4
Step 3/7 : WORKDIR $APP_PATH
Removing intermediate container eec9a41c94de
 ---> 7d5cd257a894
Step 4/7 : RUN yarn add koa
 ---> Running in e89c6232943b
yarn add v1.5.1
Done in 2.82s.
Removing intermediate container e89c6232943b
 ---> 58250e3262f5
Step 5/7 : COPY app.js ./
 ---> 5e58144a70b7
Step 6/7 : EXPOSE $PORT
 ---> Running in f67421f15a05
Removing intermediate container f67421f15a05
 ---> a15d8c641778
Step 7/7 : CMD node app.js
 ---> Running in 066e5b7d828b
Removing intermediate container 066e5b7d828b
 ---> d6b38100fdd5
Successfully built d6b38100fdd5
Successfully tagged my_app_image:latest

layers

instability

Docker 102 - Creating

docker container run    \
    --name my_app       \
    --publish 9999:8888 \
    --detach my_app_image
  • name the container
  • bind host:container ports
  • run in background

Docker 102 - Creating

$ docker container logs my_app

Server running on port 8888

Inspect logs from the container running in detach mode

docker container stop mynode

Stop container (explicitly, as it's running on --detach)

Docker 102 - Creating

Docker 103 - Evergreen

Survival through impermanence

diposable

persistent

YET

container

system

/

bin

usr

var

...

foo

/

bin

usr

var

...

bar

container fs

host fs

container down

diposable

Docker 103 - Evergreen

docker container run \
    --name my_app \
    --publish 9999:8888 \
    --volume $(pwd):/myapp \
    --detach my_app_image
  • name, bind ports and run in background
  • bind filesystems

Docker 103 - Evergreen

/

bin

usr

var

...

foo

/

bin

usr

var

...

bar

container fs

host fs

container down

persistent

Docker 103 - Evergreen

References

Thank you

A step before Willy Wonka of Containers

João Daniel

Made with Slides.com