5. 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
6
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
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.
8
Base Image SSH user
base_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 >
9
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.
10
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
11
public-ext-net-01 and
node-inet-net-01 are fixed data
12. Override our built-in docker settings
12
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
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
14
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=openstackn--mtu=1400/g' /etc/default/docker ; sudo service docker restart ; sudo
ip link set mtu 1400 dev docker0"
18
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"
19
20. Test it out
We will deploy an easy docker container to test it, please put this Dockerfile
in your folder:
20
21. Test it out
Create the image:
$ docker build -t example -f Dockerfile .
21
22. Test it out
See the new image running ‘docker images’.
22
23. Test it out
Run your new image by typing ‘docker run example’
23
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.
25
30. Define services
Create a file called ‘docker-compose.yml’ in your project directory and add
the following.
30
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
31
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
32
37. Working with Docker Swarm
37
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
38
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"
40
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
41
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"
42
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.
43
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"
44
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’:
45
46. Working with your swarm
Check the images currently running on your swarm.
46
47. Working with your swarm
Run hello-world docker and see where was it.
47
49. 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