From b6868f16a9e9235405c667bc7a56f8121b9ef578 Mon Sep 17 00:00:00 2001 From: Will Sargent Date: Tue, 9 Dec 2014 10:46:04 -0800 Subject: [PATCH] Add clarification on EXPOSE and port forwarding. --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ea969ce..5e4087c 100644 --- a/README.md +++ b/README.md @@ -273,13 +273,8 @@ You can also use remote NFS volume if you're [feeling brave](http://www.tech-d.n ## Exposing ports -Exposing ports through the host container is [fiddly but doable](http://docs.docker.io/use/port_redirection/#binding-a-port-to-an-host-interface). +Exposing incoming ports through the host container is [fiddly but doable](https://docs.docker.com/reference/run/#expose-incoming-ports). -First expose the port in your Dockerfile: - -``` -EXPOSE -``` Then map the container port to the host port (only using localhost interface): @@ -287,7 +282,13 @@ Then map the container port to the host port (only using localhost interface): docker run -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage ``` -If you're running Docker in Virtualbox, you then need to forward the port there as well. It can be useful to define something in Vagrantfile to expose a range of ports so that you can dynamically map them: +If you don't want to use the `-p` option on the command line, you can persist it by using [EXPOSE](http://docs.docker.io/reference/builder/#expose): + +``` +EXPOSE +``` + +If you're running Docker in Virtualbox, you then need to forward the port there as well, using [forwarded_port](https://docs.vagrantup.com/v2/networking/forwarded_ports.html). It can be useful to define something in Vagrantfile to expose a range of ports so that you can dynamically map them: ``` Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|