How to assign domain names to containers in Docker?

So, you need to use the concept of port publishing, so that a port from your container is accessible via a port from your host. Using this, you can can setup a simple proxy_pass from an Nginx that will redirect users.mycompany.com to myhost:1337 (assuming that you published your port to 1337)

So, if you want to do this, you’ll need to setup your container to expose a certain port using:

docker run -d -p 5000:5000 training/webapp # publish image port 5000 to host port 5000

You can then from your host curl your localhost:5000 to access the container.

curl -X GET localhost:5000

If you want to setup a domain name in front, you’ll need to have a webserver instance that allows you to proxy_pass your hostname to your container.

i.e. in Nginx:

server {
  listen 80;
  server_name users.mycompany.com;
  location / {
    proxy_pass http://localhost:5000;
  }
}

I would advise you to follow this tutorial, and maybe check the docker run reference.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)