For my frontend, I have an angular application which consumes data from a node.js backend through an http call: http//server:3000.
With my current setup and config or a different setup if needed, how can restrict the backend from being accessible only to the frontend and inaccessible via any channel i.e it shouldn't be reachable by any Postman request or via browser etc but only reachable within the frontend app.
Dockerfile for the Frontend:
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Dockerfile for the server:
FROM node:lts-alpine
WORKDIR /server
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "app.js"]
Docker-compose.yml:
services:
server:
container_name: server
image: server
build:
context: ./server
dockerfile: Dockerfile
volumes:
- ./server:/app
expose:
- '3000:3000'
client:
container_name: commerce
image: commerce
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./commerce:/app
ports:
- 8080:80
depends_on:
- server
I'm wholly unfamiliar with networking in docker so detailed suggestions would be much appreciated. Thanks in advance.