大网数据广告活动
服务器运维问答

Unable to curl Nginx rhel docker container

· 52CE 我爱测

Dockerfile: FROM registry.access.redhat.com/rhel WORKDIR /usr/src RUN yum-config-manager --save --setopt=rhel-7-server-rt-beta-rpms.skip_if_unavailable=true # Install Nginx Repository RUN yum install -y http://nginx.org/packages/…

问题原文

原帖链接 · Shuaib Shaikh · CC BY-SA 3.0

Dockerfile:

FROM registry.access.redhat.com/rhel

WORKDIR /usr/src
RUN yum-config-manager --save --setopt=rhel-7-server-rt-beta-rpms.skip_if_unavailable=true

# Install Nginx Repository
RUN yum install -y http://nginx.org/packages/rhel/7/noarch/RPMS/nginx-release-rhel-7-0.el7.ngx.noarch.rpm

# Install 

RUN yum install -y nginx

# Clean up YUM
RUN yum clean all

# Disable Nginx to run on background
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose the HTTP & HTTPS ports
EXPOSE 8080

=================================

Docker build

docker build -t nginxt .

=================================

Docker run

docker run -it -p 8080:8080  nginxt

=================================

[root@ip-20-0-0-86 friday]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                    NAMES
7eaaf772b94a        nginxt              "/bin/bash"         About a minute ago   Up About a minute   0.0.0.0:8080->8080/tcp   elegant_kalam

[root@7eaaf772b94a src]# curl localhost:8080
curl: (7) Failed connect to localhost:8080; Connection refused

已采纳解答

原帖链接 · Miguel A. C. · CC BY-SA 3.0

NGINX Docker image uses port 80 to listen for http connections by default.

If you use EXPOSE 8080 in your Dockerfile you're not setting that port for NGINX to listen on, you're just saying hey my container may listen for connections to port 8080, but not NGINX use 8080 for that you should change the NGINX configuration file.

If you want to use port 8080 you can use the following docker command:

docker run -it -p 8080:80  nginxt

That way 8080 port in your host is forwarded to port 80 of your NGINX container. Also you can change EXPOSE from 8080 to EXPOSE 80 in your Dockerfile.

For your reference:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。