Coder Social home page Coder Social logo

docker-dispatch's Introduction

Docker Dispatch

Why?

Some applications have a need to create a collection of containers via a reliable stream of queued messages.

Architecture

Docker dispatch listens for properly formatted messages from RabbitMQ and creates/runs containers from pre-built images in Docker. It talks to the Docker daemon via its RESTful API and delivers responses in stdout.

architecture

Demo

demo

Install

Fetch repository:

$ go get github.com/mutaphore/docker-dispatch

Build:

$ cd $GOPATH/github.com/mutaphore/docker-dispatch
$ go build

Run

To run the dispatcher service:

$ ./docker-dispatch [options] dockerHostAddr amqpAddr

dockerHostAddr is the docker daemon host address you would like the dispatcher to connect to. This can be expressed as a TCP url or the socket path. A valid TCP url would have ip:port format such as 172.17.0.1:2375. A socket path is the unix file path to the socket which is usually like /var/run/docker.sock. Information on how to configure and run the Docker daemon can be found here

amqpAddr is the full url to RabbitMQ with format amqp://username:password@host:port. Here's the full spec. For example, a valid url would be something like amqp://guest:guest@localhost:5672/

Example:

./dockerdispatch -q myqueue 172.17.0.1:2375 amqp://guest:guest@localhost:5672

For more information on how to setup Docker to bind to different addresses see here.

Message formats

Docker dispatcher accepts JSON messages similar to the CLI command that you would give to the docker daemon. Note: all JSON keys are capitalized.

Running a container from an image (docker run)

  • Dockercmd - docker command to execute: "run"
  • Options - object containing options to pass into the docker command.
    • Name - name of container
    • Entrypoint - command to execute in container
    • Attach - attach to container file descriptors that is an array of strings selected from "STDIN", "STDOUT", "STDERR"
    • Remove - automatically remove the container when it exits
  • Image - image name to create container from
  • Cmd - exec form of command to run in container having format ["executable","param1","param2"]

Example

{
  Dockercmd: "run",
  Options: {
    Name: "hello_world",
    Attach: ["STDOUT", "STDERR"],
    Remove: true
  },
  Image: "debian:jessie"
  Cmd: ["echo", "hello world!"]
}

Stopping a container (docker stop)

  • Dockercmd - docker command to execute: "stop"
  • Options - object containing options to pass into the docker command.
    • Time - seconds to wait for stop before killing it (default 10)
  • Container - name or id of container to remove

Example

{
  Dockercmd: "stop",
  Options: {
    Time: 5
  },
  Container: "hello_world"
}

Removing a container (docker rm)

  • Dockercmd - docker command to execute: "remove"
  • Options - object containing options to pass into the docker command.
    • Volumes - remove the volumes associated with the container
    • Force - force the removal of a running container (uses SIGKILL)
  • Container - name or id of container to remove

Example

{
  Dockercmd: "remove",
  Container: "hello_world"
}

docker-dispatch's People

Contributors

mutaphore avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.