我有一个在容器内运行的GraphQL应用程序。如果先运行docker compose build
,然后运行docker compose up
,则可以通过localhost:9999/graphql
连接到它。在dockerfile中,端口转发为9999:80
。当我运行docker container ls
命令时,可以看到端口已按预期进行了转发。
我想在VS Code远程容器中运行它。选择Open folder in remote container
使我可以选择选择dockerfile或docker-compose文件来构建容器。我已经尝试过两个选项,但都不允许我从本地主机访问GraphQL游乐场。从docker-compose运行,我可以看到端口似乎以与运行docker compose up
相同的方式转发,但是我无法访问该站点。
我要去哪里错了?
更新:如果我在由vs代码构建的容器上运行docker compose up
,则可以连接到localhost和graphql游乐场。
FROM docker.removed.local/node
MAINTAINER removed
WORKDIR /opt/app
COPY package.json /opt/app/package.json
COPY package-lock.json /opt/app/package-lock.json
COPY .npmrc /opt/app/.npmrc
RUN echo "nameserver 192.168.11.1" > /etc/resolv.conf && npm ci
RUN mkdir -p /opt/app/logs
# Setup a path for using local npm packages
RUN mkdir -p /opt/node_modules
ENV PATH /opt/node_modules/.bin:$PATH
COPY ./ /opt/app
EXPOSE 80
ENV NODE_PATH /opt:/opt/app:$NODE_PATH
ARG NODE_ENV
VOLUME ["/opt/app"]
CMD ["forever", "-o", "/opt/app/logs/logs.log", "-e", "/opt/app/logs/error.log", "-a", "server.js"]
version: '3.5'
services:
server:
build: .
container_name: removed-data-graph
command: nodemon --ignore 'public/*' --legacy-watch src/server.js
image: docker.removed.local/removed-data-graph:local
ports:
- "9999:80"
volumes:
- .:/opt/app
- /opt/app/node_modules/
#- ${LOCAL_PACKAGE_DIR}:/opt/node_modules
depends_on:
- redis
networks:
- company-network
environment:
- NODE_ENV=dev
redis:
container_name: redis
image: redis
networks:
- company-network
ports:
- "6379:6379"
networks:
company-network:
name: company-network