I have a three tier application on Docker tat consists of the following: 1. An Adonis app to server as the api for the application 2. A MongoDB database 3. A NuxtJS app for the client application.
When I run the application locally with docker-compose up
it seems to start up just fine. However, when I try to access the api with postman (localhost:3333) or try to access the Next app on my browser (localhost:3000/), I get a "Could not get any response" error and a "Cannot open the page error" respectively.
I have tried exposing the ports within each component's Dockerfile, in addition to specifying port mappings on the docker-compose.yml file.
Here is my Dockerfile for the API application
# The API application
FROM node:alpine
WORKDIR home/api
COPY ./server-api/package.json .
RUN npm install
COPY ./server-api .
EXPOSE 3333
CMD ["npm", "start"]
Here is the Dockerfile for the NuxtJS application
# The Web application
FROM node:latest
WORKDIR home/app
COPY ./web-client/package.json .
RUN npm install
COPY ./web-client .
EXPOSE 3000
CMD ["npm", "start"]
Here is my docker-compose.yml file
version: '3'
services:
api:
build: ./server
restart: always
ports:
- "3333:3333"
mongodb:
image: 'mongo'
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: NoneOfYourBusiness
web:
build: ./web
restart: always
ports:
- "3000:3000"
When I send a GET request to "localhost:3333/" I expect to get a response of "test". However, I am getting a "Could not get any response" error from Postman instead.
When I go to "localhost:3000/" on by browser, I expect to get a page. Instead, it is saying it cannot connect to the server.
localhost
is always "this container". Use the other container's name in thedocker-compose.yml
file (e.g.,api
) as a host name instead.