docker容器正在运行,但仍然无法访问应用程序

smdnsysy  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(814)

我的docker compose文件似乎运行得很好,在docker Jmeter 板中,我看到适当的容器正在工作。当我去http://localhost:8080/我看到的只是一条错误消息,上面写着:“此页不工作。localhost没有发送任何数据。错误\空\响应'。我不知道怎么解决这个问题。我看到了用“0.0.0.0”替换localhost的地方,但不确定如何在这个上下文中这样做,我觉得我已经看到它与localhost一起工作,所以我不确定如何处理这些信息。我已经检查了其他来源,看看我做得不正确,并没有找到一个好的解决办法。我很想就这件事征求任何意见!
Docker

version: '3'
services:
  dev:
    image: filamentgraphql/filament-dev
    container_name: 'filament-dev-hot'
    ports: 
      - '8080:8080'
    volumes:
      - .:/usr/src/app
      - node_modules:/usr/src/app/node_modules
    command: npm run dev:hot
  redis-server:
    image: 'redis'
    volumes:
      - "./data/redis:/usr/src/app/data"
volumes:
  node_modules:

docker开发

FROM node:12.16.1
RUN npm install --global webpack
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN npm install
EXPOSE 4000

dockerfile文件

FROM node:12.16.1
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
RUN npm run build
EXPOSE 4000
ENTRYPOINT node ./server/server.js

服务器.js

const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const redis = require("redis");
require('dotenv').config();

// Mongo DB Setup
const mongoose = require('mongoose');
const MONGO_URI = process.env.MONGO_URI;
mongoose
  .connect(MONGO_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    dbName: 'Filament',
  })
  .then(() => console.log('Connected to Mongo DB'))
  .catch((err) => console.log(err));

// Redis Setup
const client = redis.createClient({
  host: 'redis-server',
  port: 6379
})
client
  .on("error", err => console.log("Error " + err))
  .on('connect', () => console.log('Redis client connected'));

// Filament Setup
const filamentMiddlewareWrapper = require('../filament-library/filamentMiddleware')
const filamentMiddleware = filamentMiddlewareWrapper(client)

// Express setup
const app = express()
const PORT = 4000;
const schema = require('./schema');

app.use(express.json())
app.use('/filament', filamentMiddleware)
app.use(
  '/graphql',
  graphqlHTTP((req) => ({
    schema,
    graphiql: true,
    context: {
      req,
    }
  })),
);

app.listen(PORT, '0.0.0.0', () => console.log(`GraphQL server is on port: ${PORT}`));

包.json

"scripts": {
    "test": "jest",
    "build": "webpack",
    "client": "webpack-dev-server --hot",
    "start": "nodemon server/server.js",
    "json-server": "json-server --watch fake-database.json",
    "dev": "npm run client & npm run start & npm run json-server & redis-server",
    "dev:hot": "npm run client & npm run start"
u4dcyp6a

u4dcyp6a1#

打开的端口和发布的端口不匹配。你需要修理你的车 docker-compose.yml ,在 .services.dev.ports.[0] (将第二个端口更改为节点内部打开的端口):

version: '3'
services:
  dev:
    image: filamentgraphql/filament-dev
    container_name: 'filament-dev-hot'
    ports:
      # Fix port here
      - '8080:4000'
    volumes:
      - .:/usr/src/app
      - node_modules:/usr/src/app/node_modules
    command: npm run dev:hot
  redis-server:
    image: 'redis'
    volumes:
      - "./data/redis:/usr/src/app/data"
volumes:
  node_modules:

相关问题