【问题标题】:nginx container not connectingnginx容器未连接
【发布时间】:2020-08-17 03:44:19
【问题描述】:

我已经部署了一个 nginx 容器,并且暴露了端口 8080:80,但是当我执行 curl localhost:8080 时,我得到“Recv failure: Connection reset by peer”。我已允许使用端口 8080 的入站规则来允许传入流量通过容器。

【问题讨论】:

  • 你的主机8080连接到容器的8080上。
  • 正如@Lamanus 所说,那里有些问题。你能分享你用来运行容器的命令吗?
  • 请分享你的 docker run 命令

标签: amazon-web-services docker devops


【解决方案1】:

欢迎雨果·卡尔德隆,

我没有找到你的任何代码,但我想在这里添加一个很好的例子,解释如何启动一个简单的 Nginx 服务器。

我的结构目录

|____nginx
| |____Dockerfile
| |____default.conf
|____docker-compose.yml

./docker-compose.yml

version: '3'
services: 
  nginx:
    restart: always
    build: 
      dockerfile: Dockerfile
      context: ./nginx
    ports:
      - '8080:80'

nginx/default.conf

server {
    listen 80;

    location / {
        return 200 'Hello world!';
    }
}

nginx/Dockerfile

FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf

执行以下命令。

docker-compose up -d

前面的命令将运行一个nginx 容器

curl http://localhost:8080

执行 curl 后,您应该会收到如下消息。

Hello world!

如果您需要更改消息或在default.conf 文件中添加新逻辑,请确保运行docker-compose build 命令,然后再次运行docker-compose up -d,最后新的更改将添加到容器中。

希望对您和其他用户有用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多