Nova Docker: Metadata service doesn't work

Bug #1259267 reported by Daniel Kuffner on 2013-12-09
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Daniel Kuffner

Bug Description

I was playing around with cloud-init. I wanted to use cloud init as substitute for the missing environment variables feature.
The basic idea is to define variables in the user data and inject the them before starting the service.

docker run -e "MY_Variable=MyValue" -d centos

would look like in openstack:

nova boot --image centos:latest --user-data "MY_Variable=MyValue" myinstance

Unfortunately does the metadata service not work inside of a docker container. After some testing I figured out that the reason for that is that a container uses as default gateway the docker network (docker ip address). The metadata service simple rejects the call since the IP address of docker container is not associated with the nova instance.

Note: The metadata service itself can be accessed ( but it is not possible to access the actual data ( - Status 404)

I was able to work around the issue by simply changing the route inside the container:

# Hack: In order to receive data from the metadata service we must make sure we resolve the data via our nova network.
# A docker container in openstack has two NICs.
# - eth0 has a IP address on the docker0 bridge which is usually an e.g. IP address.
# - pvnetXXXX is a IP address assigned by nova.
# Extract the NIC name of the nova network.
NOVA_NIC=$(ip a | grep pvnet | head -n 1 | cut -d: -f2)

while [ "$NOVA_NIC" == "" ] ; do
   echo "Find nova NIC..."
   sleep 1
   NOVA_NIC=$(ip a | grep pvnet | head -n 1 | cut -d: -f2)

echo "Device $NOVA_NIC found. Wait until ready."
sleep 3

# Setup a network route to insure we use the nova network.
echo "[INFO] Create default route for $NOVA_NIC. Gateway"
ip r r default via dev $NOVA_NIC

# Shutdown eth0 since icps will fetch enabled enterface for streaming.
ip l set down dev eth0

This approach is obviously a poor solution since it has certain expectation of the network.

Another solution might be extend the docker driver to add a firewall rule which will masquerade requests on with the actual nova network IP address

I third solution would need improvements in docker. If docker would have a network mode which allows to assign the IP from outside this issue would be solved. That of course is a just which must be accepted by the docker community.

Network Threads:

Simple script to test metadata inside the container:

status=$(curl -I -s -o /dev/null -w "%{http_code}"

while [ $status != '200' ]; do
   echo "Cannot access metadata, status: '$status', try again..."
   date # easier to see in docker logs that loop is still running.
   status=$(curl -I -s -o /dev/null -w "%{http_code}"
   sleep 1

echo "Yes we got some user data:"

description: updated
description: updated
description: updated
description: updated
description: updated
summary: - Docker: Metadata service doesn't work
+ Nova Docker: Metadata service doesn't work
Daniel Kuffner (daniel-kuffner) wrote :

Change Set:
It seems to be good enough to just change the default route of the container to the nova network.

Changed in nova:
status: New → In Progress
assignee: nobody → Daniel Kuffner (daniel-kuffner)

Submitter: Jenkins
Branch: master

commit 709410d243a97d35c3da314b41bab039eac75736
Author: Daniel Kuffner <email address hidden>
Date: Sun Dec 15 09:53:17 2013 +0100

    Nova Docker: Metadata service doesn't work

    The metadata services rejects the request because the remote IP address
    belongs to the docker network. The remote IP address is correct by using
    the nova network as default route.

    Change-Id: I410a9bfea560f669515b31db7f007515b4d5c4e7
    Closes-Bug: #1259267
    Closes-Bug: #1261021

Changed in nova:
status: In Progress → Fix Committed
Changed in nova:
milestone: none → icehouse-3
Thierry Carrez (ttx) on 2014-03-05
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx) on 2014-04-17
Changed in nova:
milestone: icehouse-3 → 2014.1
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers