Add a way to expose a port without publishing

Add a way to expose a port without publishing

Use the existing “expose” section of container yaml files, which has always been publishing ports. Expose a port if a single port number is specified (80). Publish if a port mapping is specified ("80:80", "127.0.0.1:20080:80").

diff --git a/README.md b/README.md
index 4fd4a63..9afa70d 100644
--- a/README.md
+++ b/README.md
@@ -82,7 +82,7 @@ expose:
   - "127.0.0.1:20080:80"
 `‍``
 
-Expose port 22 inside the container on port 2222 on ALL local host interfaces. In order to bind to only one interface, you may specify the host's IP address as `([<host_interface>:[host_port]])|(<host_port>):<container_port>[/udp]` as defined in the [docker port binding documentation](http://docs.docker.com/userguide/dockerlinks/)
+Publish port 22 inside the container on port 2222 on ALL local host interfaces. In order to bind to only one interface, you may specify the host's IP address as `([<host_interface>:[host_port]])|(<host_port>):<container_port>[/udp]` as defined in the [docker port binding documentation](http://docs.docker.com/userguide/dockerlinks/). To expose a port without publishing it, specify only the port number (e.g., `80`).
 
 
 #### volumes:
diff --git a/launcher b/launcher
index 19fbf45..ec20826 100755
--- a/launcher
+++ b/launcher
@@ -425,7 +425,7 @@ RUBY
         p e
        end
     end
-    puts ports.map {|p| "-p\n#{p}"}.join("\n")
+    puts ports.map { |p| p.to_s.include?(':') ? "-p\n#{p}" : "--expose\n#{p}" }.join("\n")
 RUBY
 
     tmp_input_file=$(mktemp)

GitHub sha: 16fb17cf

3 Likes