I need to set up proxying between docker containers. In my variations, the containers are accessible from the host machine, but they cannot see each other.
Check the availability of containers via curl.
What am I doing wrong? How is it correct?
docker-compose.yml
version: "2.4"
services:
nginx:
image: nginx:1.17.2-alpine
container_name: nginx
volumes:
- ./default.nginx:/etc/nginx/conf.d/default.conf
ports:
- 8989:8989
frontend:
container_name: frontend
environment:
- VIRTUAL_HOST=localhost:3000
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- 3000:3000
backend:
container_name: backend
environment:
- VIRTUAL_HOST=localhost:1337
build:
context: ./backend
dockerfile: Dockerfile
ports:
- 1337:1337
front
FROM keymetrics/pm2:latest-alpine
ENV NPM_CONFIG_LOGLEVEL error
WORKDIR /usr/src/app
RUN apk update && apk upgrade && apk add --no-cache bash git openssh
RUN apk --no-cache add curl
COPY . .
RUN yarn install
RUN yarn build:ssr
EXPOSE 3000 1337
CMD [ "pm2-runtime", "start", "pm2.json" ]</blockquote>
back
<blockquote>FROM strapi/base:latest
RUN yarn global add strapi
RUN mkdir /srv/app && chown 1000:1000 -R /srv/app
RUN apk --no-cache add curl
WORKDIR /srv/app
EXPOSE 1337 3000
COPY . .
RUN yarn
# CMD ["strapi", "develop"]
CMD ["strapi", "start"]
default.nginx
server {
listen 8989;
server_name localhost;
location / {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location localhost:3000 {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location localhost:3000/graphql {
proxy_pass http://backend:1337/graphql;
# proxy_pass http://backend:1337;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~/graphql {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
# proxy_pass http://backend:1337/graphql;
proxy_pass http://localhost:1337/graphql;
}
location localhost:1337 {
proxy_pass http://backend:1337;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# location ~ /.ht {
# deny all;
# }
}
I ask for help in this matter, because I'm a beginner. If its ready-made configuration for my task, please provide.
question from:
https://stackoverflow.com/questions/65905292/docker-how-to-set-up-proxying 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…