Browse code

Update ambassador image, use the socat -t option

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>

Aidan Hobson Sayers authored on 2015/10/06 19:43:06
Showing 2 changed files
... ...
@@ -107,7 +107,7 @@ to the world (via the `-p 6379:6379` port mapping):
107 107
     $ sudo ./contrib/mkimage-unittest.sh
108 108
     $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 docker-ut sh
109 109
 
110
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
110
+    $ socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
111 111
 
112 112
 Now ping the Redis server via the ambassador:
113 113
 
... ...
@@ -116,7 +116,7 @@ Now go to a different server:
116 116
     $ sudo ./contrib/mkimage-unittest.sh
117 117
     $ docker run -t -i --expose 6379 --name redis_ambassador docker-ut sh
118 118
 
119
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
119
+    $ socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
120 120
 
121 121
 And get the `redis-cli` image so we can talk over the ambassador bridge.
122 122
 
... ...
@@ -127,8 +127,8 @@ And get the `redis-cli` image so we can talk over the ambassador bridge.
127 127
 
128 128
 ## The svendowideit/ambassador Dockerfile
129 129
 
130
-The `svendowideit/ambassador` image is a small `busybox` image with
131
-`socat` built in. When you start the container, it uses a small `sed`
130
+The `svendowideit/ambassador` image is based on the `alpine` image with
131
+`socat` installed. When you start the container, it uses a small `sed`
132 132
 script to parse out the (possibly multiple) link environment variables
133 133
 to set up the port forwarding. On the remote host, you need to set the
134 134
 variable using the `-e` command line option.
... ...
@@ -139,19 +139,21 @@ Will forward the local `1234` port to the remote IP and port, in this
139 139
 case `192.168.1.52:6379`.
140 140
 
141 141
     #
142
-    #
143
-    # first you need to build the docker-ut image
144
-    # using ./contrib/mkimage-unittest.sh
145
-    # then
146
-    #   docker build -t SvenDowideit/ambassador .
147
-    #   docker tag SvenDowideit/ambassador ambassador
142
+    # do
143
+    #   docker build -t svendowideit/ambassador .
148 144
     # then to run it (on the host that has the real backend on it)
149
-    #   docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 ambassador
145
+    #   docker run -t -i -link redis:redis -name redis_ambassador -p 6379:6379 svendowideit/ambassador
150 146
     # on the remote host, you can set up another ambassador
151
-    #   docker run -t -i --name redis_ambassador --expose 6379 sh
152
-
153
-    FROM    docker-ut
154
-    MAINTAINER      SvenDowideit@home.org.au
155
-
156
-
157
-    CMD     env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
147
+    #    docker run -t -i -name redis_ambassador -expose 6379 -e REDIS_PORT_6379_TCP=tcp://192.168.1.52:6379 svendowideit/ambassador sh
148
+    # you can read more about this process at https://docs.docker.com/articles/ambassador_pattern_linking/
149
+
150
+    # use alpine because its a minimal image with a package manager.
151
+    # prettymuch all that is needed is a container that has a functioning env and socat (or equivalent)
152
+    FROM	alpine:3.2
153
+    MAINTAINER	SvenDowideit@home.org.au
154
+
155
+    RUN apk update && \
156
+    	apk add socat && \
157
+    	rm -r /var/cache/
158
+    
159
+    CMD	env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat -t 100000000 TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \& wait/' | sh
... ...
@@ -72,18 +72,20 @@ accelerating `docker build` significantly (indicated by `Using cache` -
72 72
 see the [`Dockerfile` Best Practices
73 73
 guide](/articles/dockerfile_best-practices/#build-cache) for more information):
74 74
 
75
-    $ docker build -t SvenDowideit/ambassador .
76
-    Uploading context 10.24 kB
77
-    Uploading context
78
-    Step 1 : FROM docker-ut
79
-     ---> cbba202fe96b
80
-    Step 2 : MAINTAINER SvenDowideit@home.org.au
75
+    $ docker build -t svendowideit/ambassador .
76
+    Sending build context to Docker daemon 15.36 kB
77
+    Step 0 : FROM alpine:3.2
78
+     ---> 31f630c65071
79
+    Step 1 : MAINTAINER SvenDowideit@home.org.au
81 80
      ---> Using cache
82
-     ---> 51182097be13
83
-    Step 3 : CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
81
+     ---> 2a1c91448f5f
82
+    Step 2 : RUN apk update &&      apk add socat &&        rm -r /var/cache/
84 83
      ---> Using cache
85
-     ---> 1a5ffc17324d
86
-    Successfully built 1a5ffc17324d
84
+     ---> 21ed6e7fbb73
85
+    Step 3 : CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat -t 100000000 TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \& wait/' | sh
86
+     ---> Using cache
87
+     ---> 7ea8aef582cc
88
+    Successfully built 7ea8aef582cc
87 89
 
88 90
 When you're done with your build, you're ready to look into [*Pushing a
89 91
 repository to its registry*]( /userguide/dockerrepos/#contributing-to-docker-hub).