Skip to content

Instantly share code, notes, and snippets.

@hartmantis
Created April 29, 2014 03:07
Show Gist options
  • Save hartmantis/11389800 to your computer and use it in GitHub Desktop.
Save hartmantis/11389800 to your computer and use it in GitHub Desktop.
Docker + Nginx Proxying
# Docker Upstart and SysVinit configuration file
# Customize location of Docker binary (especially for development testing).
#DOCKER="/usr/local/bin/docker"
# Use DOCKER_OPTS to modify the daemon startup options.
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
DOCKER_OPTS="-D -H 127.0.0.1:8081 -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"
# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR="/mnt/bigdrive/docker-tmp"
upstream docker {
server unix:/var/run/docker.sock fail_timeout=0;
}
server {
listen 80;
location / {
proxy_pass http://docker;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_buffering off;
}
}
require 'docker'
# Direct Docker socket or...
socket = 'http://192.168.33.10:4243'
# ...Nginx proxy socket
#socket = 'http://192.168.33.10'
dockerfile = <<-EOH.gsub(/^ /, '')
FROM ubuntu:12.04
RUN apt-get update
RUN echo HELLO
EOH
opts = {}
docker_connection = Docker::Connection.new(socket, read_timeout: 300)
image = Docker::Image.build(dockerfile, opts, docker_connection) do |chunk|
puts "CHUNK: #{chunk}"
end
# Hitting Docker directly #
CHUNK: {"stream":"Step 0 : FROM ubuntu:12.04\n"}
CHUNK: {"stream":" ---\u003e c0fe63f9a4c1\n"}
CHUNK: {"stream":"Step 1 : RUN apt-get update\n"}
CHUNK: {"stream":" ---\u003e Using cache\n"}
CHUNK: {"stream":" ---\u003e 39e90547aa66\n"}
CHUNK: {"stream":"Step 2 : RUN echo HELLO\n"}
CHUNK: {"stream":" ---\u003e Using cache\n"}
CHUNK: {"stream":" ---\u003e dad6e71caa9f\n"}
CHUNK: {"stream":"Successfully built dad6e71caa9f\n"}
# Hitting Docker proxied through Nginx #
CHUNK: {"stream":"Step 0 : FROM ubuntu:12.04\n"}
{"stream":" ---\u003e c0fe63f9a4c1\n"}
{"stream":"Step 1 : RUN apt-get update\n"}
CHUNK: {"stream":" ---\u003e Using cache\n"}
CHUNK: {"stream":" ---\u003e 39e90547aa66\n"}
CHUNK: {"stream":"Step 2 : RUN echo HELLO\n"}
CHUNK: {"stream":" ---\u003e Using cache\n"}
CHUNK: {"stream":" ---\u003e dad6e71caa9f\n"}
CHUNK: {"stream":"Successfully built dad6e71caa9f\n"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment