Frontend and API in different containersView other answers to this thread
3.4K+ developers have started their personal blogs on Hashnode in the last one month.
Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more
As Dong Nguyen stated, you'll probably need a reverse-proxy to map your API container to the myapp.com/api location. I'd recommend using Nginx, have a look at Frank Rousseau's answer below for an example with Nginx.
In addition to that, I wanted to recommend you a few things:
You should stop using the --link option
--link option to link container is deprecated since Docker 1.9 and will probably be removed in future versions: docs.docker.com/engine/userguide/networking..
What you should do instead is to create your own Docker network and start your containers inside that network. Containers started inside a user-defined network will be able to communicate by using their container names.
Here is a small example:
$ docker network create myapp $ docker run -d -p 27017:27017 --name mongodb mongo $ docker run -d -p 3000:3000 --name backend myapp/backend $ docker run -d -p 80:80 --name frontend myapp/frontend
Give a try to docker-compose
Compose is tool for defining and running multi-container Docker application. You'll be able to define what services (mongodb, backend, frontend) that make up your app in a single YAML file and manage it using a single command-line. It's pretty handy ! Have a look here for more information: docs.docker.com/compose/overview