.I have 4 containers: client/server/nginx/mongo
My app is working however when I am trying to do a post to: let url = ‘http://myserver:3000/api/register’ from the client to the server, I am getting a timeout.
from within the client container I can ping upstream client.
When I do docker port on these containers I am getting no ports, however like mentioned, I can see my app which works on port 4200.
What could be the reason for the timeout, how do I know if the port forward is working. I spent days trying to figure this out, I really feel I am making a little mistake somewhere…
upstream my-server {
server myserver:3000;
}
upstream client {
server client:4200;
}
server {
location / {
proxy_pass http://client;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /api/ {
proxy_pass http://my-server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
version: '3'
services:
nginx:
build: ./nginx
# Map Nginx port 80 to the local machine's port 80
ports:
- "80:80"
depends_on:
- client
- myserver
# Build the container using the client Dockerfile
client:
build: ./
# This line maps the contents of the client folder into the container.
volumes:
- ./:/usr/src/app
myserver:
build: ./express-server
volumes:
- ./express-server:/usr/src/server
depends_on:
- mongo
# Link the client container so that Nginx will have access to it
mongo:
environment:
- AUTH=yes
- MONGO_INITDB_ROOT_USERNAME=superAdmin
- MONGO_INITDB_ROOT_PASSWORD=admin123
image: mongo
volumes:
- /var/mongodata/data:/data/db
# Create a new image from the base nodejs 7 image.
FROM node:8.1.4-alpine as builder
# Create the target directory in the imahge
RUN mkdir -p /usr/src/app
# Set the created directory as the working directory
WORKDIR /usr/src/app
# Copy the package.json inside the working directory
COPY package.json /usr/src/app
# Install required dependencies
RUN npm install
# Copy the client application source files. You can use .dockerignore to exlcude files.
Works just as .gitignore does.
COPY . /usr/src/app
# Open port 4200. This is the port that our development server uses
EXPOSE 4200
# Start the application. This is the same as running ng serve.
CMD ["npm", "start"]