Преглед на файлове

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

Update ambassador image, use the socat -t option
Sven Dowideit преди 9 години
родител
ревизия
b826215c57
променени са 2 файла, в които са добавени 40 реда и са изтрити 35 реда
  1. 28 25
      docs/articles/ambassador_pattern_linking.md
  2. 12 10
      docs/reference/builder.md

+ 28 - 25
docs/articles/ambassador_pattern_linking.md

@@ -81,42 +81,43 @@ On the Docker host (192.168.1.52) that Redis will run on:
     ^D
 
     # add redis ambassador
-    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 busybox sh
+    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 alpine:3.2 sh
 
 In the `redis_ambassador` container, you can see the linked Redis
 containers `env`:
 
-    $ env
+    / # env
     REDIS_PORT=tcp://172.17.0.136:6379
     REDIS_PORT_6379_TCP_ADDR=172.17.0.136
     REDIS_NAME=/redis_ambassador/redis
     HOSTNAME=19d7adf4705e
+    SHLVL=1
+    HOME=/root
     REDIS_PORT_6379_TCP_PORT=6379
-    HOME=/
     REDIS_PORT_6379_TCP_PROTO=tcp
-    container=lxc
     REDIS_PORT_6379_TCP=tcp://172.17.0.136:6379
     TERM=xterm
     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
     PWD=/
+    / # exit
 
 This environment is used by the ambassador `socat` script to expose Redis
 to the world (via the `-p 6379:6379` port mapping):
 
     $ docker rm redis_ambassador
-    $ sudo ./contrib/mkimage-unittest.sh
-    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 docker-ut sh
-
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
+    $ CMD="apk update && apk add socat && sh"
+    $ docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 alpine:3.2 sh -c "$CMD"
+    [...]
+    / # socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:172.17.0.136:6379
 
 Now ping the Redis server via the ambassador:
 
 Now go to a different server:
 
-    $ sudo ./contrib/mkimage-unittest.sh
-    $ docker run -t -i --expose 6379 --name redis_ambassador docker-ut sh
-
-    $ socat TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
+    $ CMD="apk update && apk add socat && sh"
+    $ docker run -t -i --expose 6379 --name redis_ambassador alpine:3.2 sh -c "$CMD"
+    [...]
+    / # socat -t 100000000 TCP4-LISTEN:6379,fork,reuseaddr TCP4:192.168.1.52:6379
 
 And get the `redis-cli` image so we can talk over the ambassador bridge.
 
@@ -127,8 +128,8 @@ And get the `redis-cli` image so we can talk over the ambassador bridge.
 
 ## The svendowideit/ambassador Dockerfile
 
-The `svendowideit/ambassador` image is a small `busybox` image with
-`socat` built in. When you start the container, it uses a small `sed`
+The `svendowideit/ambassador` image is based on the `alpine:3.2` image with
+`socat` installed. When you start the container, it uses a small `sed`
 script to parse out the (possibly multiple) link environment variables
 to set up the port forwarding. On the remote host, you need to set the
 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
 case `192.168.1.52:6379`.
 
     #
-    #
-    # first you need to build the docker-ut image
-    # using ./contrib/mkimage-unittest.sh
-    # then
-    #   docker build -t SvenDowideit/ambassador .
-    #   docker tag SvenDowideit/ambassador ambassador
+    # do
+    #   docker build -t svendowideit/ambassador .
     # then to run it (on the host that has the real backend on it)
-    #   docker run -t -i --link redis:redis --name redis_ambassador -p 6379:6379 ambassador
+    #   docker run -t -i -link redis:redis -name redis_ambassador -p 6379:6379 svendowideit/ambassador
     # on the remote host, you can set up another ambassador
-    #   docker run -t -i --name redis_ambassador --expose 6379 sh
+    #    docker run -t -i -name redis_ambassador -expose 6379 -e REDIS_PORT_6379_TCP=tcp://192.168.1.52:6379 svendowideit/ambassador sh
+    # you can read more about this process at https://docs.docker.com/articles/ambassador_pattern_linking/
 
-    FROM    docker-ut
-    MAINTAINER      SvenDowideit@home.org.au
+    # use alpine because its a minimal image with a package manager.
+    # prettymuch all that is needed is a container that has a functioning env and socat (or equivalent)
+    FROM	alpine:3.2
+    MAINTAINER	SvenDowideit@home.org.au
 
+    RUN apk update && \
+    	apk add socat && \
+    	rm -r /var/cache/
 
-    CMD     env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
+    CMD	env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat -t 100000000 TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \& wait/' | sh

+ 12 - 10
docs/reference/builder.md

@@ -78,18 +78,20 @@ the `Using cache` message in the console output.
 (For more information, see the [Build cache section](../articles/dockerfile_best-practices.md#build-cache)) in the
 `Dockerfile` best practices guide:
 
-    $ docker build -t SvenDowideit/ambassador .
-    Uploading context 10.24 kB
-    Uploading context
-    Step 1 : FROM docker-ut
-     ---> cbba202fe96b
-    Step 2 : MAINTAINER SvenDowideit@home.org.au
+    $ docker build -t svendowideit/ambassador .
+    Sending build context to Docker daemon 15.36 kB
+    Step 0 : FROM alpine:3.2
+     ---> 31f630c65071
+    Step 1 : MAINTAINER SvenDowideit@home.org.au
      ---> Using cache
-     ---> 51182097be13
-    Step 3 : CMD env | grep _TCP= | sed 's/.*_PORT_\([0-9]*\)_TCP=tcp:\/\/\(.*\):\(.*\)/socat TCP4-LISTEN:\1,fork,reuseaddr TCP4:\2:\3 \&/'  | sh && top
+     ---> 2a1c91448f5f
+    Step 2 : RUN apk update &&      apk add socat &&        rm -r /var/cache/
      ---> Using cache
-     ---> 1a5ffc17324d
-    Successfully built 1a5ffc17324d
+     ---> 21ed6e7fbb73
+    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
+     ---> Using cache
+     ---> 7ea8aef582cc
+    Successfully built 7ea8aef582cc
 
 When you're done with your build, you're ready to look into [*Pushing a
 repository to its registry*](../userguide/dockerrepos.md#contributing-to-docker-hub).