Docker example for frontend and backend application
I am learning how to use Docker, and I am in a process of setting up a simple app with Frontend and Backend using Centos+PHP+MySQL.
I have my machine:
In machine “example” i have configured 2 docker containers:
frontend: build: ./frontend volumes: - ./frontend:/var/www/html - ./infrastructure/logs/frontend/httpd:/var/logs/httpd ports: - "80" links: - api api: build: ./api volumes: - ./api:/var/www/html - ./infrastructure/logs/api/httpd:/var/logs/httpd ports: - "80" links: - mysql:container_mysql
The issue I am facing is when I access the docker container, I need to specify a port number for either FRONTEND (32771) or BACKEND (32772).
Is this normal or is there a way to create hostnames for the API and Frontend of the application?
How does this work on deployment to AWS?
Thanks in advance.
One Solution collect form web for “Docker example for frontend and backend application”
If you’re running docker 1.9 or 1.10, and use the 2.0 format for your
docker-compose.yml, you can directly access other services through either their “service” name, or “container” name. See my answer on this question, which has a basic example to illustrate this; https://stackoverflow.com/a/36245209/1811501
Because the connection between services goes through the private container-container network, you don’t need to use the randomly assigned ports, so if a service publishes/exposes port 80, you can simply connect through port 80