This fine piece of engineering may or may not give you the time it was a moment ago towards the past. Unless called before the time expected in return. Or after the delay unavoidable once the inherent foward-latency has been elapsing.
Details of architectural design
The brains, heart and guts of this container reside in
require 'gserver' # # A server that returns the time in seconds since 1970. # class TimeServer < GServer def initialize(port=10001, host="0.0.0.0", *args) super(port, host, *args) end def serve(io) red = io.readline puts red io.print red io.puts Time.now end end # Run the server with logging enabled (it's a separate thread). server = TimeServer.new server.start server.join
First, do note that it is clever enough to bind to all network interfaces (0.0.0.0) and not just
localhost as you could expect. This is to allow you to query it from the outside of the container. Even from beyond the outside. Handy, huh !?
Putting it to service
docker run -d -P ameuret/clock:v1.6 ruby fido.rb
Witness the power
Check the port assigned to the internal server:
docker ps ID IMAGE COMMAND STATUS PORTS bc3346 ameuret/clock:v1.6 "ruby fido.rb" Up 4 seconds 0.0.0.0:49153->10001/tcp
Query it !
curl localhost:49153/ GET / HTTP/1.1 2014-10-13 14:36:51 +0100
I found really creative that it replies using part of the question before venturing into stating the time