What are the best practice to access a docker instances from the outside.

I'm planning to deploy several docker instances (node.js, php, mysql), either all packaged in one or through docker links between containers.

It is possible to control port on the host machine for each docker instances, but then what should be the best practice to access those instance from the outside. I would rather have subdomain only, and get rid of the forwarded port of the instance.


user@server:~/sandbox/docker-nginx$ sudo docker ps

3fc7c57ed66c    docker-wordpress-nginx:latest   /bin/bash /start.sh   3 days ago          Up 3 days>80/tcp   evil_poincare       

Expected behavior : Request wordpress.domain.com access the wordpress inside that docker instance, through the port 49153, but browser do not rewrite the Location with that port.

I had a look/tried several approaches, but none gave me that functionality :

  • bouncy with routes.json files
  • reverse proxying with nginx in host machine, but still have the port in the redirected url
  • skydock sounds great but no multi host support yet
  • pipework looks good also, but the disclaimer warn us that it should be provided by docker complex scenarios soon.

Any thoughts on that problem, and any recommendation on the best practice would be greatly appreciated, maybe I'm just missing something.

3 Answers 3


I am using nginx for this, it works very well (for me). From your comments sounds like its not working as your expecting however...

A simplistic configuration that should work is below.


server {
  server_name wordpress.domain.com;
  location / {
      proxy_redirect off;
      proxy_set_header Host $host ;
      proxy_set_header X-Real-IP $remote_addr ;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
      proxy_pass http://localhost:49153;
  • Thanks for the proposal, it is barely the configuration I used, and unfortunately it is the one, which doesn't remove the port, the wordpress.domain.com is accessible, but then I'm redirected to a page with the port added. Commented Mar 9, 2014 at 23:55

The best pratice is AVOID do any command line tasks in a Docker container, the best way to get your nginx containers up and running exactly like you expect is by creating a custom image and ADD your configuration file in image's Dockerfile.

You can find a detailed description on how to create your custom image with custom configuration here.


My answer is a bit late : for future reference, you should take a look at https://github.com/jwilder/nginx-proxy. This tool automatically generates appropriate Nginx configuration to forward incoming requests to Docker containers (based on subdomains).

First, launch the nginx-proxy:

docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

For instance, if you want to redirect sub.domain.com to a specific container, simply set the VIRTUAL_HOST container environment variable to "sub.domain.com":

docker run -e VIRTUAL_HOST=sub.domain.com ...

Here is a detailed tutorial I wrote about it: http://blog.florianlopes.io/host-multiple-websites-on-single-host-docker.

It matches perfectly your expected behavior.

  • Welcome to ServerFault! Ideally your answer would contain the details/code/instructions necessary for addressing the OP's issue; links can change/go dead/stale over time, thus using them to provide the full answer is frowned upon. It's better to provide the full details here, and a link for reference.
    – Castaglia
    Commented Apr 6, 2016 at 4:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .