simple docker hosting in fiware lab

Post on 20-Feb-2017

378 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

fernando.lopezaguilar@telefonica.com

@flopezaguilar

Table of content

Overview

Basic Set Up: FIWARE set up, docker-machine

Docker Engine

Docker-compose

Docker Swarm

References

2

Basic Set Up

3

……

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

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

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

7

FIWARE set up: Allocate at least one public IP

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

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. ‘username@gmail.com’

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

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

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.

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

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

13

Overview of the FIWARE Lab running instance

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

15

Get info of the running docker machine

Docker Engine

16

17

Test execution of hello-world container

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"

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"

20

Test it out

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

21

Test it out

Create the image:

$ docker build -t example -f Dockerfile .

22

Test it out

See the new image running ‘docker images’.

23

Test it out

Run your new image by typing ‘docker run example’

Docker-compose

24

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.

26

Create web server

Create app.py file with the content:

27

Create web server

Create ‘requirements.txt’.

Create ‘Dockerfile’.

28

Create web server

Create image ‘web’.

29

Create web server

Check the new image ‘web’

30

Define services

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

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

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

33

See the application running

34

Other commands

See what is currently running:

Stop your services once you’ve finished with them:

35

Other commands

Remove stopped containers:

Docker Swarm

36

37

Working with Docker Swarm

Docker Swarm is native clustering for Docker.

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

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

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

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"

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

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"

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.

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"

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’:

46

Working with your swarm

Check the images currently running on your swarm.

47

Working with your swarm

Run hello-world docker and see where was it.

References

48

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

50

http://fiware.org

http://lab.fiware.org

Follow @FIWARE on Twitter !

Thanks!

top related