How to publish a web site running in a docker container on production?

I have a web application running in a docker container on production server. Now I need to make API requests to this application. So, I have two possibilities: 1) Link a domain 2) Make requests directly by IP

I'm using a cloud server for that. In my previous experience I linked the domain to a folder. But now I don't know how to link the domain to a running container on ip_addr:port.

I found this link https://docs.docker.com/v17.12/datacenter/ucp/2.2/guides/user/services/use-domain-names-to-access-services/ but it's for docker enterprice. Using of that is impossible for the moment.

Upvotes: 2

Views: 2519

Answers (2)

Akash Sharma
Akash Sharma

Reputation: 757

Best way is to use kubernetes because it will ease many operations. But docker-compose can also be used.

If you want to simply deploy using docker it can be done by mapping hostPort to containerPort.

Upvotes: 0

Frank Yucheng Gu
Frank Yucheng Gu

Reputation: 1889

To expose a docker application to the public without using compose or other orchestration tools like Kubernetes, you can use the docker run -p hostPort:containerPort option to expose your container port. Make sure your application is listening on 0.0.0.0:[container port] inside your container. To access the service externally, you would use the host's IP, and the port that the container port has been mapped to.

See more here

If you want to link to a domain, you can update your DNS records to point your domain to your host IP address.

Hope this helps!

Upvotes: 1

Related Questions