Skip to content

Latest commit

 

History

History
231 lines (196 loc) · 5.91 KB

3. Examples.md

File metadata and controls

231 lines (196 loc) · 5.91 KB

Pipework reference: jpetazzo/pipework
Readme / Intro / Install / Usage / Examples / Config

Examples

Single Invocation

docker run -v /var/run/docker.sock:/docker.sock --privileged=true --pid=host --net=host \
  kvaps/pipework --help

Syntax:
pipework <hostinterface> [-i containerinterface] <guest> <ipaddr>/<subnet>[@default_gateway] [macaddr][@vlan]
pipework <hostinterface> [-i containerinterface] <guest> dhcp [macaddr][@vlan]
pipework --wait [-i containerinterface]

Background Daemon

App / Service Container:

docker run --name='mycontainer' --net=none -e 'pipework_cmd=eth0 @CONTAINER_NAME@ dhcp' myrepo/myimage

Pipework Container:

docker run --restart=always -v /var/run/docker.sock:/docker.sock --privileged=true --pid=host --net=host \
  -e run_mode=batch,daemon -e host_routes=true kvaps/pipework

Create a file named docker-compose.yml. Example:

myapp:
  image: myrepo/myapp
  environment:
    - pipework_cmd=eth0 @CONTAINER_NAME@ 192.168.1.101/[email protected] 0a:00:01:01:01:01

pipework:
  image: kvaps/pipework
  restart: always
  volumes:
    - /var/run/docker.sock:/docker.sock
  privileged: true
  pid: host # THIS REQUIRES COMPOSE v1.3.0 & DOCKER v1.6.0
  net: host
  environment:
    - run_mode=batch,daemon
    - host_routes=true
    - route_add_delay=1

Using crane is very much like docker compose. You just need create a file named crane.yml instead. But it's very similar. Example:

containers:
  myapp:
    image: myrepo/myapp
    run:
      env:
        - pipework_cmd=eth0 @CONTAINER_NAME@ 192.168.1.101/[email protected] 0a:00:01:01:01:01

  pipework:
    image: kvaps/pipework
    run:
      restart: always
      volume:
        - /var/run/docker.sock:/docker.sock
      privileged: true
      pid: host
      net: host
      detach: true
      env:
        - run_mode=batch,daemon
        - host_routes=true
        - route_add_delay=1

All Options

  • This crane.yml shows all of the config environment variables enabled at once.
  • For documentation on each option see section [4. Config](4. Config.md).
  • N.B. Some extraneous whitespace has been added to improve readability.
containers:

  a_container:
    image: busybox
    run:
      cmd: tail -f /dev/null
      detach: true
      net: none
      env:
        - pipework_key=APScQYDITSrNt+9YS13INVP6m/3oH/iSlh4Gc7R or any un-guessable string
        - pipework_cmd_dhcp1=        eth0 -i eth0 @CONTAINER_NAME@ dhcp
        - pipework_host_route_dhcp1= true
        - pipework_cmd_ip=           eth0 -i eth1 @CONTAINER_NAME@ 192.168.101.@INSTANCE@/24
        - pipework_host_route_ip=    true
        - pipework_host_route_arping=true
        - pipework_cmd_create_private_bridge= br1 -i eth2 @CONTAINER_NAME@ dhcp

  another_container:
    image: busybox
    run:
      cmd: tail -f /dev/null
      detach: true
      env:
        - another_pipework_cmd=        eth0 -i eth1 @CONTAINER_ID@   dhcp
        - another_pipework_host_route= true
        - pipework_cmd_that_creates_private_bridge= br1 -i eth2 @CONTAINER_NAME@ dhcp

  pipework:
    image: kvaps/pipework
    run:
      restart: always
      volume:
        - /var/run/docker.sock:/docker.sock
      privileged: true
      pid: host
      net: host
      detach: true
      env:
        - key=APScQYDITSrNt+9YS13INVP6m/3oH/iSlh4Gc7R or any un-guessable string
        - run_mode=manual,batch,daemon
        - event_filters=image=busybox,container=a_container
        - host_routes=true
        - host_route_arping=true
        - sleep=60
        - debug=true
        - cleanup_wait=30
        - retry_delay=5
        - inter_delay=15
        - route_add_delay=1
        - cmd_for_manual_mode= eth0 -i eth3 a_container dhcp
        - another_manual_cmd=  eth0 -i eth3 another_container dhcp
        - host_route_for_manual_mode= true
        - another_host_route=         true

Create a file named pipework.yaml. Example:

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: pipework
  namespace: kube-system
  labels:
    app: pipework
spec:
  template:
    metadata:
      labels:
        name: pipework
    spec:
      hostPID: true
      hostIPC: true
      hostNetwork: true
      containers:
        - image: kvaps/pipework
          name: pipework
          securityContext:
            privileged: true
          env:
            - name: run_mode
              value: "batch,daemon"
            - name: host_routes
              value: "true"
            - name: route_add_delay
              value: "1"
          volumeMounts:
            - name: docker-sock
              mountPath: /docker.sock
      volumes:
        - name: docker-sock
          hostPath:
              path: /var/run/docker.sock

and nginx.yaml for example:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  template:
    metadata:
      labels:
        app: nginx
      annotations:
        pipework_cmd_int0: "eth0 @CONTAINER_NAME@ 192.168.1.101/[email protected]"
    spec:
      containers:
      - name: nginx
        image: nginx