Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and...

44
Aurelijus Banelis Docker on VDS

Transcript of Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and...

Page 1: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Aurelijus Banelis

Docker on VDS

Page 2: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Aurelijus Banelis

[email protected] developer

Page 3: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Docker on VDS

Page 4: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

What is docker?

Is it possible? Why not?

Dev/prod and configs

Testing and debugging

Version control and state

Why VDS? Why docker?Yo

u w

ill le

arn

Page 5: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Why VDS?Why docker?

Wanted new technologies on my old Virtual Dedicated Server

Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 6: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Page 7: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Page 8: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Markdowndocumentation

Very smart bash script

Provision with puppet

Provision with saltstack

Page 9: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Markdowndocumentation

Very smart bash script

Provision with puppet

Provision with saltstack

Page 10: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

What is docker?

User-friendly containerization tools

Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 11: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

What is docker?

Source: https://www.docker.com/

Page 12: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

One line to run

docker-compose up

*Docker-compose is a docker wrapper, written in Python

Page 13: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Isolated apps

Page 14: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Tools: docker-compose

$ docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf -d -p 8080:80 nginx

services: image: nginx volumes: - ./some/nginx.conf:/etc/nginx/nginx.conf ports: - "8080:80"

docker-compose.yml

Page 15: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Is it possible?Why not always?

Possible on some VDS, but mine used bad kernel

Docker on VDS Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 16: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

One line to rundocker-compose up

Page 17: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

One line to rundocker-compose up

If docker is installed

*Docker-compose is a docker wrapper, written in Python. There was less problems installing it, than docker itself

Page 18: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Old distribution?

Page 19: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Old distribution?

Not linux?

Install from .deb on Ubuntu 14.04

Page 20: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Old distribution?

Newest kernel

Not linux?

Your Linux kernel version 2.6.32-042stab113.12 can be unstable running docker.

Please upgrade your kernel to 3.10.0.http://forumas.dedikuoti.lt/showthread.php?t=602

Install from .deb on Ubuntu 14.04

Native forOSX and Win

Page 21: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Ended up on AWS

Page 22: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Ended up on AWS

Stable HDD

Page 23: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Ended up on AWS

Static IP

Stable HDD

Page 24: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Ended up on AWS

https://aws.amazon.com/

Similar price

Static IP

Stable HDD

Page 25: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Dev and prod environments

Using multiple docker-compose.yml

Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 26: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Via multiple filesdocker-compose

-f docker-compose.yml -f docker-compose.stage.yml

-f docker-compose.live.yml up -d

services: web: environment: - PHP_AB_LT_HOST=aurelijus.banelis.lt - JAVA_WEBSITE_HOST=auginte.com - JAVA_DEMOAPP_HOST=demo.auginte.com php_ab_lt: environment: - DB_PASSWORD=h2Jk_PHP_IMPRESS_qIefEgtjeSFlA

docker-compose.live.yml

Page 27: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Update on runvolumes: - ./my-nginx/run.sh:/custom/run.shcommand: - "/custom/run.sh"

docker-compose..yml

https://gist.github.com/aurelijusb/ce672b88fff5aa2340cc4f97d65511dd

# .... sed -e "s#\${$IN}#$OUT#g" < ${CFG_TMP} > ${CFG_DEST}# ....nginx -g 'daemon off;'

run.sh

Do not use envsubst - to not change $uri, $document_root, ...

Page 28: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Availabilitydocker-compose..yml

web: ports: - "127.0.0.1:1380:80" - "127.0.0.1:13443:443"

Ports not colliding with default applications

Friends in same WiFi will not see your work

Page 29: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Availability

web: ports: - "0.0.0.0:80:80" - "0.0.0.0:443:443" restart: always

docker-compose..yml

https://docs.docker.com/v1.10/engine/userguide/networking/default_network/binding/

web: ports: - "127.0.0.1:1380:80" - "127.0.0.1:13443:443"

docker-compose..stage.yml

Ports not colliding with default applications

Friends in same WiFi will not see your work

Open to the users

Auto-restart,if application crashes

Page 30: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Testing and debugging

Usually docker command-line

Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 31: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

docker ps -a

STATUS PORTS NAMESUp 9 days 3306/tcp mysql_ab_ltExited (0) 9 days ago mysql_ab_lt_provision

Page 32: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

docker ps -a

STATUS PORTS NAMESUp 9 days 3306/tcp mysql_ab_ltExited (0) 9 days ago mysql_ab_lt_provision

docker logs -f mysql_ab_lt_provision

Page 33: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

docker ps -a

STATUS PORTS NAMESUp 9 days 3306/tcp mysql_ab_ltExited (0) 9 days ago mysql_ab_lt_provision

docker logs -f mysql_ab_lt_provision

docker exec -it web sh

Page 34: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Insert bash in entrypoint script

Page 35: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Docker inspectdocker inspect -f '{{.Name}} - {{.NetworkSettings.Networks.docker_default.IPAddress }}' $(docker ps -aq)

Insert bash in entrypoint script

Page 36: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

ssh -i ~/.ssh/secret.pem -L 127.0.0.1:18081:172.18.0.3:8081 [email protected]

Docker inspect

SSH & Port forwarding

docker inspect -f '{{.Name}} - {{.NetworkSettings.Networks.docker_default.IPAddress }}' $(docker ps -aq)

Insert bash in entrypoint script

Page 37: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Version control and state

.gitignore raw data, add fields for provisioning

Why

VD

S?

Why

do

cker

?

Wha

t is

dock

er?

Is it

po

ssib

le?

Why

not

?

Dev

/pro

d an

d co

nfig

sTe

stin

g an

d de

bugg

ing

Vers

ion

cont

rol a

nd

stat

e

Page 38: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Mount vs Buildcontainer_name: webimage: nginx:1.11.1-alpinevolumes: - ../releases/php-ab-lt/$REV/install:/releases/php_ab_lt/$REV/install - ../releases/php-ab-lt/$REV/Ip:/releases/php_ab_lt/$REV/Ip - ../releases/php-ab-lt/$REV/Plugin:/releases/php_ab_lt/$REV/Plugin - ../releases/php-ab-lt/$REV/Theme:/releases/php_ab_lt/$REV/Theme - ../releases/php-ab-lt/$REV/vendor:/releases/php_ab_lt/$REV/vendor - ../releases/php-ab-lt/$REV/admin.php:/releases/php_ab_lt/$REV/admin.php - ../releases/php-ab-lt/$REV/favicon.ico:/releases/php_ab_lt/$REV/favicon.ico - ../releases/php-ab-lt/$REV/index.php:/releases/php_ab_lt/$REV/index.php - ../releases/php-ab-lt/$REV/robots.txt:/releases/php_ab_lt/$REV/robots.txt

Page 39: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Mount vs Builddocker-php-ext-install mbstring pdo_mysql gd

Page 40: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Mount vs Build

Page 41: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Data: dump/mergemysql_ab_lt: volumes: - /custom/data/mysql-ab-lt/stage:/var/lib/mysql

mysql_ab_lt_provision: environment: - MYSQL_ROOT_PASSWORD=h2JfESFlA - IMPORT_DBNAME=ab_lt_stage - IMPORT_FILE=/custom/dumps/aurelijusb_ip.sql - REPLACE_FROM=aurelijus.banelis.lt - REPLACE_TO=aurelijus.banelis.stage

Page 42: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

Problem/Context

Data: dump/mergemysql_ab_lt: volumes: - /custom/data/mysql-ab-lt/stage:/var/lib/mysql

mysql_ab_lt_provision: environment: - MYSQL_ROOT_PASSWORD=h2JfESFlA - IMPORT_DBNAME=ab_lt_stage - IMPORT_FILE=/custom/dumps/aurelijusb_ip.sql - REPLACE_FROM=aurelijus.banelis.lt - REPLACE_TO=aurelijus.banelis.stage

bin/auginte-server -Dprovision=${PROVISION}

Page 43: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

What is docker?

Is it possible? Why not?

Dev/prod and configs

Testing and debugging

Version control and state

Why VDS? Why docker?Yo

u ha

ve le

arne

d

Page 44: Docker on VDS · What is docker? Is it possible? Why not? Dev/prod and configs Testing and debugging Version control and state Why VDS? Why docker? You will learn

What is docker?

Is it possible? Why not?

Dev/prod and configs

Testing and debugging

Version control and state

Why VDS? Why docker?Yo

u ha

ve le

arne

d That’s it. Questions?

?Slides hosted using Docker:

https://aurelijus.banelis.lt/prezentations/nta-2016/Docker-on-VDS-v2.pdf