Skip to content

Instantly share code, notes, and snippets.

@nerdalert
Last active April 22, 2016 00:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdalert/45a49f1b216e9a10c77e to your computer and use it in GitHub Desktop.
Save nerdalert/45a49f1b216e9a10c77e to your computer and use it in GitHub Desktop.

Example Viewing Docker Events via the Swarm/Docker API Event Stream

QuickStart

Example Docker event stream:

# (Optionally) grab the latest experimental for Macvlan/Ipvlan.
$ wget https://experimental.docker.com/builds/Linux/x86_64/docker-latest

### Start Engine w/ Swarm API Port bound
$ sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

### Start Event Stream
$ sudo docker -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock events

# Create a network
$ docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth1 mcv

# View the network etc.
$ curl http://localhost:2375/networks | python -m json.tool

Full Docker API Event Stream Example with Output

Start Docker engine with the Swarm API port bound

$ sudo docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

Monitor events with the following

./docker-latest -H tcp://0.0.0.0:2376 events

Create a network:

docker network create -d macvlan \
  --subnet=172.16.86.0/24 \
  --gateway=172.16.86.2 \
  -o parent=eth0 mcv

That will stream the events to the console when you for example create a network:

(event stream output) network create 2995fc449e7f220a0b3d048286895b43b38e532dbcaed69b2c0b39599b4e00d5 (name=mcv, type=macvlan)

Take the UUID streamed above which the the ID of the network you created and go a GET on the ID.

$ curl http://localhost:2375/networks/2995fc449e7f220a0b3d048286895b43b38e532dbcaed69b2c0b39599b4e00d5

The GET on networks/id returns all of the information about the network.

{
  "Name": "mcv",
  "Id": "2995fc449e7f220a0b3d048286895b43b38e532dbcaed69b2c0b39599b4e00d5",
  "Scope": "local",
  "Driver": "macvlan",
  "EnableIPv6": false,
  "IPAM": {
    "Driver": "default",
    "Options": {
    },
    "Config": [
      {
        "Subnet": "172.16.86.0/24",
        "Gateway": "172.16.86.2"
      }
    ]
  },
  "Internal": false,
  "Containers": {
  },
  "Options": {
    "parent": "eth0"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment