Kevin Laslo
Kevin Laslo

Reputation: 377

How to map ports with - Express + Docker + Azure

I am completely stuck on the following.

Trying to setup a express app in docker on an Azure VM.

1) VM is all good after using docker-machine create -driver azure ...

2) Build image all good after:

//Dockerfile
FROM iojs:onbuild

ADD package.json package.json
ADD src src

RUN npm install

EXPOSE 8080
CMD ["node", "src/server.js"]

Here's where I'm stuck:

I have tried all of the following plus many more:

• docker run -P (Then adding end points in azure)
• docker run -p 80:8080
• docker run -p 80:2756 (2756, the port created during docker-machine create)
• docker run -p 8080:80

If someone could explain azure's setup with VIP vs internal vs docker expose.

So at the end of all this, every port that I try to hit with Azure's:

AzureVirtualIP:ALL_THE_PORT

I just always get back a ERR_CONNECTION_REFUSED

For sure the express app is running because I get the console log info.

Any ideas?

Thanks

Upvotes: 2

Views: 1198

Answers (1)

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24483

Starting from the outside and working your way in, debugging:

Outside Azure

<start your container on the Azure VM, then>

$ curl $yourhost:80

On the VM

$ docker run -p 80:8080 -d laslo
882a5e774d7004183ab264237aa5e217972ace19ac2d8dd9e9d02a94b221f236
$ docker ps
CONTAINER ID  IMAGE         COMMAND             CREATED        STATUS        PORTS             NAMES
64f4d98b9c75  laslo:latest  node src/server.js  5 seconds ago  up 5 seconds  0.0.0.0:80->8080  something_funny
$ curl localhost:80

That 0.0.0.0:80->8080 shows you that your port forwarding is in effect. If you run other containers, don't have the right privileges or have other networking problems, Docker might give you a container without forwarding the ports.

If this works but the first test didn't, then you didn't open the ports to your VM correctly. It could be that you need to set up the Azure endpoint, or that you've got a firewall running on the VM.

In the container

$ docker run -p 80:8080 --name=test -d laslo
882a5e774d7004183ab264237aa5e217972ace19ac2d8dd9e9d02a94b221f236
$ docker exec it test bash
# curl localhost:8080

In this last one, we get inside the container itself. Curl might not be installed, so maybe you have to apt-get install curl first.

If this doesn't work, then your Express server isn't listening on port 80, and you need to check the setup.

Upvotes: 4

Related Questions