simple docker hosting in fiware lab

51
http:// bit.ly/fiware-docker http :// www.fiware.org http:// lab.fiware.org Follow @FIWARE on Twitter Simple Docker hosting FIWARE Lab Fernando López Telefonica I+D Contact email f [email protected] @flopezaguilar

Upload: fernando-lopez-aguilar

Post on 20-Feb-2017

379 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Simple docker hosting in FIWARE Lab

http://bit.ly/fiware-dockerhttp://www.fiware.orghttp://lab.fiware.orgFollow @FIWARE on Twitter

Simple Docker hosting FIWARE LabFernando LópezTelefonica I+D

Contact email

[email protected]

@flopezaguilar

Page 2: Simple docker hosting in FIWARE Lab

Table of content

Overview

Basic Set Up: FIWARE set up, docker-machine

Docker Engine

Docker-compose

Docker Swarm

References

2

Page 3: Simple docker hosting in FIWARE Lab

Basic Set Up

3

Page 4: Simple docker hosting in FIWARE Lab

……

Node

….

Node

….

clientclient

docker-enginedocker-machinedocker-composedocker-swarm

docker api

Any tool based

onDocker-api

docker cli

4

Simple Docker hosting on FIWARERemotely Managed by Docker Client

Page 5: Simple docker hosting in FIWARE Lab

FIWARE Lab Cloud Docker Hosting Overview

Host docker on FIWARE, but control from local docker client

• Docker engine: creates and runs Docker containers.

• Docker Hub: hosted registry service for managing and sharing docker container

images.

• Docker-Compose: defines multi-container applications.

• Docker-Machine: automates container provisioning.

• Docker Swarm: is used to host clustering and containers.

Prerequisites:

• FIWARE User.

• User’s organization is allowed to allocate at least one floating point IP.

• Install docker on local machine.

5

Page 6: Simple docker hosting in FIWARE Lab

6

FIWARE set up: Add security group for docker-machine

Create ‘docker-machine’ security group.

Edit security group rules and add:

SSH: Port 22

Docker Daemon Port 2376

Docker Swarm Master Port: 3376

Auto allocated user ports:

32768-33768

Other User Ports e.g. 8080

Page 7: Simple docker hosting in FIWARE Lab

7

FIWARE set up: Allocate at least one public IP

Page 8: Simple docker hosting in FIWARE Lab

8

FIWARE set up: Get image name and SSH user

We recommend the use of base images of FIWARE, which are configured to resolve security issues.

The values that you need to configure are the following:

The rest of images are not supported for docker management.

Base Image SSH userbase_centos_7 centos

base_debian_8 debian

base_ubuntu_14.04 ubuntu

Page 9: Simple docker hosting in FIWARE Lab

9

docker-machine: create docker host on fiware

• You can obtain the following data from the info button in the cloud.lab.fiware.org:

$ export OS_REGION_NAME=<fiware region, Region in Info modal window, e.g. 'Spain2‘>

$ export OS_TENANT_NAME=<user’s organization, Tenant name in Info modal window, e.g. ‘username cloud’>

$ export OS_USERNAME=<user’s email address, User name in Info modal window, e.g. ‘[email protected]

$ export OS_PASSWORD=<user’s password, your password in FIWARE Lab>

$ export OS_AUTH_URL=<Authentication URL in Info modal window >

Page 10: Simple docker hosting in FIWARE Lab

10

docker-machine: create docker host on fiware

You need to specify the strategy used to authenticate an user:

$ export OS_AUTH_STRATEGY='keystone’

Last but not least, you have to specify the User Domain name:

$ export OS_DOMAIN_NAME=‘default’

I recommend to put all of them in a configuration file.

Page 11: Simple docker hosting in FIWARE Lab

11

docker-machine: create docker host on fiware

$ docker-machine create --driver openstack --openstack-ssh-user ubuntu --openstack-image-name base_ubuntu_14.04 --openstack-flavor-name m1.large --openstack-floatingip-pool public-ext-net-01 --openstack-sec-groups docker-machine --openstack-net-name node-int-net-01 FIWARE-Docker

public-ext-net-01 andnode-inet-net-01 are fixed data

Page 12: Simple docker hosting in FIWARE Lab

12

Override our built-in docker settings

Once complete, we want to override our built-in docker settings to point to our new machine. We can do that by issuing:

$ eval $(docker-machine env FIWARE-Docker)

VERY IMPORTANT, do not forget

it

Page 13: Simple docker hosting in FIWARE Lab

13

Overview of the FIWARE Lab running instance

Page 14: Simple docker hosting in FIWARE Lab

14

Upgrade your docker machine

Finally, we want to ensure that our machine is totally up to date by issuing the following:

$ docker-machine upgrade FIWARE-Docker

Page 15: Simple docker hosting in FIWARE Lab

15

Get info of the running docker machine

Page 16: Simple docker hosting in FIWARE Lab

Docker Engine

16

Page 17: Simple docker hosting in FIWARE Lab

17

Test execution of hello-world container

Page 18: Simple docker hosting in FIWARE Lab

18

IP Forwarding and MTU configuration (Ubuntu) In order to work with an instance in the FIWARE Lab, it is needed that you

configure the IP Forwarding in this instance. Execute the following command:

docker-machine ssh FIWARE-Docker "sudo sed -i 's/.*net.ipv4.ip_forward=.*/net.ipv4.ip_forward=1/g' /etc/sysctl.conf ; sudo sysctl -p"

Besides, we need to change the MTU in Spain2 by the value that we have configured in the network. To do it, execute:

docker-machine ssh FIWARE-Docker "sudo sed -i 's/--label provider=openstack/--label provider=openstack\n--mtu=1400/g' /etc/default/docker ; sudo service docker restart ; sudo ip link set mtu 1400 dev docker0"

Page 19: Simple docker hosting in FIWARE Lab

19

IP Forwarding and MTU configuration (CentOS & Debian) In case of CentOS Imagen the configuration of IP Forwarding can be done

with the following command:

$ docker-machine ssh FIWARE-Docker -tt ”sudo /sbin/sysctl -w net.ipv4.ip_forward=1; sudo sysctl -p"

Besides, we need to change the MTU in Spain2 by the value that we have configured in the network. To do it, execute:

$ docker-machine ssh FIWARE-swarm-master -tt "sudo sed -i 's/--label provider=openstack/--label provider=openstack --mtu=1400/g' /etc/systemd/system/docker.service ; sudo systemctl daemon-reload ; sudo systemctl restart docker ; sudo ip link set mtu 1400 dev docker0"

Page 20: Simple docker hosting in FIWARE Lab

20

Test it out

We will deploy an easy docker container to test it, please put this Dockerfile in your folder:

Page 21: Simple docker hosting in FIWARE Lab

21

Test it out

Create the image:

$ docker build -t example -f Dockerfile .

Page 22: Simple docker hosting in FIWARE Lab

22

Test it out

See the new image running ‘docker images’.

Page 23: Simple docker hosting in FIWARE Lab

23

Test it out

Run your new image by typing ‘docker run example’

Page 24: Simple docker hosting in FIWARE Lab

Docker-compose

24

Page 25: Simple docker hosting in FIWARE Lab

25

Docker compose: Get and application running in one command

Build a simple Python web application running on Docker Compose.

Test: deploy an application uses the Flask framework and increments a value in Redis.

Page 26: Simple docker hosting in FIWARE Lab

26

Create web server

Create app.py file with the content:

Page 27: Simple docker hosting in FIWARE Lab

27

Create web server

Create ‘requirements.txt’.

Create ‘Dockerfile’.

Page 28: Simple docker hosting in FIWARE Lab

28

Create web server

Create image ‘web’.

Page 29: Simple docker hosting in FIWARE Lab

29

Create web server

Check the new image ‘web’

Page 30: Simple docker hosting in FIWARE Lab

30

Define services

Create a file called ‘docker-compose.yml’ in your project directory and add the following.

Page 31: Simple docker hosting in FIWARE Lab

31

Build and run your app with Compose

From your project directory, run:

$ docker-compose up

See the deployed server running in:

$ http://0.0.0.0:5000

KEEP IN MIND,This port has to be

open in your Security Group

Page 32: Simple docker hosting in FIWARE Lab

32

Build and run your app with Compose

Get the IP of the docker-machine:

The IP of the server will be:

http://130.206.122.3:5000

Page 33: Simple docker hosting in FIWARE Lab

33

See the application running

Page 34: Simple docker hosting in FIWARE Lab

34

Other commands

See what is currently running:

Stop your services once you’ve finished with them:

Page 35: Simple docker hosting in FIWARE Lab

35

Other commands

Remove stopped containers:

Page 36: Simple docker hosting in FIWARE Lab

Docker Swarm

36

Page 37: Simple docker hosting in FIWARE Lab

37

Working with Docker Swarm

Docker Swarm is native clustering for Docker.

Turn a pool of Docker hosts into a single, virtual Docker host.

Page 38: Simple docker hosting in FIWARE Lab

38

Generate a discovery token using the Docker Swarm image Execute the swarm create command in a container.

Export the token to a variable:

$ export TOKEN=e924ca5408f5e88052d580bee034b145

Page 39: Simple docker hosting in FIWARE Lab

39

Launch the Swarm manager

Create a swarm manager under OpenStack:

$ docker-machine create \

-d openstack \

--openstack-ssh-user centos \

--openstack-image-name base_centos_7 \

--openstack-flavor-name m1.small \

--openstack-floatingip-pool public-ext-net-01 \

--openstack-sec-groups docker-machine \

--openstack-net-name node-int-net-01 \

--swarm \ --swarm-master \ --swarm-discovery token://$TOKEN \ FIWARE-swarm-master

Page 40: Simple docker hosting in FIWARE Lab

40

Docker Swarm: create master

Remember configure IP Forwarding and MTU in Spain2 region:

$ docker-machine ssh FIWARE-swarm-master -tt "sudo /sbin/sysctl -w net.ipv4.ip_forward=1; sudo sysctl -p"

Besides, we need to change the MTU in Spain2 by the value that we have configured in the network. To do it, execute:

$ docker-machine ssh FIWARE-swarm-master -tt "sudo sed -i 's/--label provider=openstack/--label provider=openstack --mtu=1400/g' /etc/systemd/system/docker.service ; sudo systemctl daemon-reload ; sudo systemctl restart docker ; sudo ip link set mtu 1400 dev docker0"

Page 41: Simple docker hosting in FIWARE Lab

41

Create a swarm node agents

Execute the following command to create an agent in Spain region:

$ docker-machine create \

-d openstack \

--openstack-ssh-user debian \

--openstack-image-name base_debian_8 \

--openstack-flavor-name m1.small \

--openstack-floatingip-pool public-ext-net-01 \

--openstack-sec-groups docker-machine \

--openstack-net-name node-int-net-01 \

--swarm \ --swarm-discovery token://$TOKEN \ FIWARE-swarm-agent-00

Page 42: Simple docker hosting in FIWARE Lab

42

Create a swarm node agents

Remember configure IP Forwarding and MTU in Spain region:

$ docker-machine ssh FIWARE-swarm-agent-00 -tt "sudo /sbin/sysctl -w net.ipv4.ip_forward=1; sudo sysctl -p"

Besides, we need to change the MTU in Spain by the value that we have configured in the network. To do it, execute:

$ docker-machine ssh FIWARE-swarm-agent-00 -tt "sudo sed -i 's/--label provider=openstack/--label provider=openstack --mtu=1400/g' /etc/systemd/system/docker.service ; sudo systemctl daemon-reload ; sudo systemctl restart docker ; sudo ip link set mtu 1400 dev docker0"

Page 43: Simple docker hosting in FIWARE Lab

43

Create a swarm node agents

Add another agent called swarm-agent-01 in Spain region:

$ docker-machine create \

-d openstack \

--openstack-ssh-user debian \

--openstack-image-name base_debian_8 \

--openstack-flavor-name m1.small \

--openstack-floatingip-pool public-ext-net-01 \

--openstack-sec-groups docker-machine \

--openstack-net-name node-int-net-01 \

--swarm \ --swarm-discovery token://$TOKEN \ FIWARE-swarm-agent-01

Remember that we are using ‘OS_REGION_NAME=Spain2’ but you can select any other region in FIWARE Lab.

Page 44: Simple docker hosting in FIWARE Lab

44

Docker Swarm: create master

Remember configure IP Forwarding and MTU in Spain region:

$ docker-machine ssh FIWARE-swarm-agent-01 -tt "sudo /sbin/sysctl -w net.ipv4.ip_forward=1; sudo sysctl -p"

Besides, we need to change the MTU in Spain by the value that we have configured in the network. To do it, execute:

$ docker-machine ssh FIWARE-swarm-agent-01 -tt "sudo sed -i 's/--label provider=openstack/--label provider=openstack --mtu=1400/g' /etc/systemd/system/docker.service ; sudo systemctl daemon-reload ; sudo systemctl restart docker ; sudo ip link set mtu 1400 dev docker0"

Page 45: Simple docker hosting in FIWARE Lab

45

Working with your swarm

Point your Docker environment to the machine running the swarm master:

$ eval $(docker-machine env -swarm FIWARE-swarm-master)

Get information of your new swarm with command ‘docker info’:

Page 46: Simple docker hosting in FIWARE Lab

46

Working with your swarm

Check the images currently running on your swarm.

Page 47: Simple docker hosting in FIWARE Lab

47

Working with your swarm

Run hello-world docker and see where was it.

Page 48: Simple docker hosting in FIWARE Lab

References

48

Page 49: Simple docker hosting in FIWARE Lab

References

How to work with FIWARE Lab: http://bit.ly/fiware-lab-cloud

Welcome to the docker Docs: https://docs.docker.com/

FIWARE Lab: https://cloud.lab.fiware.org

FIWARE GE docker images: https://hub.docker.com/u/fiware/dashboard/

FIWARE Catalogue: https://catalogue.fiware.org/

49

Page 50: Simple docker hosting in FIWARE Lab

50

Page 51: Simple docker hosting in FIWARE Lab

http://fiware.org

http://lab.fiware.org

Follow @FIWARE on Twitter !

Thanks!