Giter Club home page Giter Club logo

whoami's Introduction

whoami

A minimal(5.0MB+) docker image with a http server that echos hostname(identifies itself) with health check support.

This docker image can be used to demostrate and validate load balance ability of your service.

Usage

Run a simple server

$ docker run -d --name echo -p 80:3000 cizixs/whoami
$ curl http://127.0.0.1
2c47ad631c82

By default container exposes port 3000, and returns container hostname(short id) as response.

Control what is returned

You can control what is returned by setting MESSAGE environment variable(the following example is illustrated under docker 1.12 swarm mode):

➜  docker service create -e MESSAGE="viola" -p 3000:3000 --replicas=2 whoami:v0.4
➜  curl http://127.0.0.1:3000
viola from bf8cf715445d
➜  curl http://127.0.0.1:3000
viola from 15d94216ff07

Check the logs

And every container outputs requests to stdout, which is accessible by standard docker logs:

➜  docker logs bf8cf7
2016/11/04 03:25:35 start serving...
2016/11/04 03:25:51 [GET] at "/" takes 41.015µs
2016/11/04 03:25:53 [GET] at "/" takes 26.656µs

Health Check

whoami exposes a health check endpoint at /health, which tells you if the service is working well. If the service is ok, it will return ok with status 200, otherwise it will return Oops! with status 500. You can toggle the health status by send a post request to /toggle.hz:

➜  curl http://127.0.0.1:8007/health                  
ok
➜  curl -X POST http://127.0.0.1:8007/toggle.hz 
done.
➜  curl http://127.0.0.1:8007/health                
Oops!%                          

NOTE: The health endpoint is only for test purpose, it does not affect other endpoints.

Build

Create the binaries with go build:

CGO_ENABLED=0 go build -a -ldflags '-s' .

For more infromation about the parameters, please refer to this blog.

Then, build the docker image:

docker build -t whoami:v1.0 .

whoami's People

Contributors

cizixs avatar

Watchers

 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.