Browse code

Merge pull request #16801 from aidanhs/aphs-add-socat-t

Update ambassador image, use the socat -t option

Sven Dowideit authored on 2015/10/20 13:24:25
Showing 2 changed files
... ...
@@ -81,42 +81,43 @@ On the Docker host (192.168.1.52) that Redis will run on:
81 81
     ^D
82 82
 
83 83
     # add redis ambassador
84
-    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 busybox sh
84
+    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 alpine:3.2 sh
85 85
 
86 86
 In the `redis_ambassador` container, you can see the linked Redis
87 87
 containers `env`:
88 88
 
89
-    $ env
89
+    / # env
90 90
     REDIS_PORT=tcp://172.17.0.136:6379
91 91
     REDIS_PORT_6379_TCP_ADDR=172.17.0.136
92 92
     REDIS_NAME=/redis_ambassador/redis
93 93
     HOSTNAME=19d7adf4705e
94
+    SHLVL=1
95
+    HOME=/root
94 96
     REDIS_PORT_6379_TCP_PORT=6379
95
-    HOME=/
96 97
     REDIS_PORT_6379_TCP_PROTO=tcp
97
-    container=lxc
98 98
     REDIS_PORT_6379_TCP=tcp://172.17.0.136:6379
99 99
     TERM=xterm
100 100
     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
101 101
     PWD=/
102
+    / # exit
102 103
 
103 104
 This environment is used by the ambassador `socat` script to expose Redis
104 105
 to the world (via the `-p 6379:6379` port mapping):
105 106
 
106 107
     $ docker rm redis_ambassador
107
-    $ sudo ./contrib/mkimage-unittest.sh
108
-    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 docker-ut sh
109
-
110
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
108
+    $ CMD="apk update && apk add socat && sh"
109
+    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 alpine:3.2 sh -c "$CMD"
110
+    [...]
111
+    / # socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
111 112
 
112 113
 Now ping the Redis server via the ambassador:
113 114
 
114 115
 Now go to a different server:
115 116
 
116
-    $ sudo ./contrib/mkimage-unittest.sh
117
-    $ docker run -t -i --expose 6379 --name redis_ambassador docker-ut sh
118
-
119
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
117
+    $ CMD="apk update && apk add socat && sh"
118
+    $ docker run -t -i --expose 6379 --name redis_ambassador alpine:3.2 sh -c "$CMD"
119
+    [...]
120
+    / # socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
120 121
 
121 122
 And get the `redis-cli` image so we can talk over the ambassador bridge.
122 123
 
... ...
@@ -127,8 +128,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:3.2` 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 +140,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
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/
152 149
 
153
-    FROM    docker-ut
154
-    MAINTAINER      SvenDowideit@home.org.au
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
155 154
 
155
+    RUN apk update && \
156
+    	apk add socat && \
157
+    	rm -r /var/cache/
156 158
 
157
-    CMD     env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
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
... ...
@@ -78,18 +78,20 @@ the `Using cache` message in the console output.
78 78
 (For more information, see the [Build cache section](../articles/dockerfile_best-practices.md#build-cache)) in the
79 79
 `Dockerfile` best practices guide:
80 80
 
81
-    $ docker build -t SvenDowideit/ambassador .
82
-    Uploading context 10.24 kB
83
-    Uploading context
84
-    Step 1 : FROM docker-ut
85
-     ---> cbba202fe96b
86
-    Step 2 : MAINTAINER SvenDowideit@home.org.au
81
+    $ docker build -t svendowideit/ambassador .
82
+    Sending build context to Docker daemon 15.36 kB
83
+    Step 0 : FROM alpine:3.2
84
+     ---> 31f630c65071
85
+    Step 1 : MAINTAINER SvenDowideit@home.org.au
87 86
      ---> Using cache
88
-     ---> 51182097be13
89
-    Step 3 : CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
87
+     ---> 2a1c91448f5f
88
+    Step 2 : RUN apk update &&      apk add socat &&        rm -r /var/cache/
90 89
      ---> Using cache
91
-     ---> 1a5ffc17324d
92
-    Successfully built 1a5ffc17324d
90
+     ---> 21ed6e7fbb73
91
+    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
92
+     ---> Using cache
93
+     ---> 7ea8aef582cc
94
+    Successfully built 7ea8aef582cc
93 95
 
94 96
 When you're done with your build, you're ready to look into [*Pushing a
95 97
 repository to its registry*](../userguide/dockerrepos.md#contributing-to-docker-hub).