NAIS

- Og hvem er vi?

Line

  • Master fra UiO
  • Jobbet i NAV siden mars
  • Kubernetes-frelst og skulle gjerne bytta ut Macen mot en Linux-maskin

Kyrre

  • Master fra UiO
  • Jobbet i NAV siden januar
  • Liker seg med Ruby

Docker

- Noen som har hørt om det?

Docker Images

FROM java:openjdk-8-jdk-alpine

COPY maven /maven/

ENTRYPOINT ["java","-jar","/maven/app.jar"]
$ sudo docker build .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM java:openjdk-8-jdk-alpine
openjdk-8-jdk-alpine: Pulling from library/java

3690ec4760f9: Already exists 
cfdb77eb56b4: Pull complete 
0d438913956e: Pull complete 
Digest: sha256:63eb1c79f609dbaa2c587ba3eb772e8e453229ce91fffc378725ca16435348e9
Status: Downloaded newer image for java:openjdk-8-jdk-alpine
 ---> f23144173f4f
Step 2 : COPY maven /maven/
 ---> 40d1f13c325e
Removing intermediate container 0f9ab0ab158d
Step 3 : ENTRYPOINT java -jar /maven/kontaktregister.jar
 ---> Running in 079de001d0aa
 ---> 0ba9ba7944dc
Removing intermediate container 079de001d0aa
Successfully built 0ba9ba7944dc
$ sudo docker build .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM java:openjdk-8-jdk-alpine
 ---> f23144173f4f
Step 2 : COPY maven /maven/
 ---> Using cache
 ---> 40d1f13c325e
Step 3 : ENTRYPOINT java -jar /maven/kontaktregister.jar
 ---> Using cache
 ---> 0ba9ba7944dc
Successfully built 0ba9ba7944dc

Docker

vs

Virtual Machine

Docker i produksjon

How to!

Dockerfile

FROM alpine:3.4

RUN apk update

# nginx
RUN apk add nginx
RUN mkdir -p /run/nginx

# start up
ENTRYPOINT nginx -g 'daemon off;'

Bygg

$ sudo docker build --tag nginx .
Sending build context to Docker daemon  5.12 kB
Step 1 : FROM alpine:3.4
 ---> baa5d63471ea
Step 2 : RUN apk update
 ---> Using cache
 ---> 2e5619c9caa7
Step 3 : RUN apk add nginx
 ---> Using cache
 ---> 95a4848b546b
Step 4 : RUN mkdir -p /run/nginx
 ---> Using cache
 ---> ccd52cd2286b
Step 5 : ENTRYPOINT nginx -g 'daemon off;'
 ---> Running in 79399fc4d9ce
 ---> b88fed45c51a
Removing intermediate container 79399fc4d9ce
Successfully built b88fed45c51a

Run

$ sudo docker run --detach --name nginx-demo nginx
8b7edd53dba5e178d92365243c9a1f44ade31af0fa1afb23a608533195b57409

PS og curl

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
8b7edd53dba5        nginx               "/bin/sh -c 'nginx -g"   4 seconds ago       Up 4 seconds                            nginx-demo

# Vi trenger IP for å curl
$ sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx-demo
172.17.0.3

$ curl 172.17.0.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

logs

$ sudo docker logs nginx-demo
# Doh, eksempelet logger jo ikke noe...

exec

$ sudo docker exec --interactive --tty nginx-demo sh
/ #
/ # cat /var/log/nginx/access.log 
172.17.0.1 - - [08/Nov/2016:21:23:00 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"

exec

# la oss kjøre opp noe som logger

$ sudo docker run --tty nginx-2 --name nginx-demo-2
172.17.0.1 - - [08/Nov/2016:21:40:20 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:21 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:22 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:23 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"

# ny terminal
$ sudo docker logs nginx-demo-2
172.17.0.1 - - [08/Nov/2016:21:40:20 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:21 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:22 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"
172.17.0.1 - - [08/Nov/2016:21:40:23 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0"

Push til Docker Hub

  • Dockerhub er gratis, kan ha ett privat repository
  • Må autentisere før push
  • Kan gi tillatelse til andre å pushe
    • Prosjektdeltagere
    • Byggservere
  • Images er klart til bruk med en gang etter upload

Docker hjemme

- Hvordan kan docker hjelpe deg?

Teste

  • Egne prosjekter
  • Teste andres software
  • OS
  • Databaser
  • Farlige ting

Hvorfor

  • Enkelt å rydde opp - bare å slette en container.
  • Container kan sammenlignes med å kjøre i en sandbox. Farlige ting slipper ikke ut.
docker run 
  --name postgres 
  -env POSTGRES_USER=postgres 
  -env POSTGRES_PASSWORD=postgres 
  -env POSTGRES_DB=<db-name> 
  --publish 5432:5432 
  --detach 
  postgres:latest
# Kommuniser med Postgresql i kontainer
docker exec 
  --interactiv
  --tty
  postgres psql -U postgres -c "CREATE DATABASE <db-name>"

PostgreSQL DB

Det var (nesten) alt

- noen spørsmål?

Installer Docker for windows:

https://www.docker.com/docker-windows

Made with Slides.com