Docker:8080 没有从 nginx 容器中得到响应

标签 docker ubuntu nginx devops

我正在尝试使用以下命令运行 nginx docker 容器,将其 8080 暴露给我的 8080 端口:docker run --name mycontainer -p 8080:8080 nginx结果是这样的:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2021/08/06 21:11:22 [notice] 1#1: using the "epoll" event method
2021/08/06 21:11:22 [notice] 1#1: nginx/1.21.1
2021/08/06 21:11:22 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6) 
2021/08/06 21:11:22 [notice] 1#1: OS: Linux 5.11.0-25-generic
2021/08/06 21:11:22 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2021/08/06 21:11:22 [notice] 1#1: start worker processes
2021/08/06 21:11:22 [notice] 1#1: start worker process 31
2021/08/06 21:11:22 [notice] 1#1: start worker process 32
2021/08/06 21:11:22 [notice] 1#1: start worker process 33
2021/08/06 21:11:22 [notice] 1#1: start worker process 34
2021/08/06 21:11:22 [notice] 1#1: start worker process 35
2021/08/06 21:11:22 [notice] 1#1: start worker process 36
2021/08/06 21:11:22 [notice] 1#1: start worker process 37
2021/08/06 21:11:22 [notice] 1#1: start worker process 38
如果我检查 docker ps :
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                               NAMES
7ccaaa84ftaf   nginx     "/docker-entrypoint.…"   7 minutes ago   Up 7 minutes   80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp   proxy

但是当在我的浏览器中向 https://localhost:8080 发送请求时, 没有反应,无限期地继续加载......
检查容器内的nginx服务docker exec -it proxy bash :
root@******:/# service nginx status
[ ok ] nginx is running.
任何想法?
钯。我是 docker 的新手并使用 ubuntu。

最佳答案

没有回应似乎很正常,因为以下两点:

  • 根据文档( https://hub.docker.com/_/nginx ),内部端口不是 8080,而是 80;这意味着您应该尝试以下命令:docker run --name mycontainer -p 8080:80 nginx顺便说一句,最好运行:docker run --rm -p 8080:80 nginx考虑到 正在运行的容器是短暂的 ,并且可以在停止时自动删除,这要归功于 --rm选项(因此将其命名为 --name … 是不必要的),然后在以后重新创建而不会丢失数据,因为持久数据通常存储在所谓的 Docker volumes 中.
  • 然后,您的 URL 以 https:// 开头但通常情况下,如果容器不涉及专用的 TLS 反向代理配置,则它只接受 HTTP 请求(以 http:// 开头)是正常的;因此,您应该尝试浏览以下 URL:
    http://localhost:8080

  • 但是,如果您特别有兴趣为您的 dockerized 网站提供一些 HTTPS 支持,请参阅例如this StackOverflow questionbrowse other questions involving these tags .

    关于Docker:8080 没有从 nginx 容器中得到响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68687625/

    相关文章:

    docker - Rancher容器中python客户端的smtp超时

    macos - 无法从 docker 容器访问本地网络 IP

    python - 如何在 Ubuntu 上更新 virtualenv?

    php - 替换为新日志文件后,访问日志将不会记录

    docker - AWS ECS EC2与 Jenkins 连续部署

    ubuntu - 在 docker 镜像中生成所有语言环境

    ruby-on-rails - 将多个 Rails 应用程序部署到 DigitalOcean

    c# - 关于使用 Nginx 将 Web 请求代理到基于 .Net HttpListener 的 Json 服务的想法

    docker - gcloud错误:(gcloud.app.deploy)错误响应:[3]

    python - 如何将gensim引入pycharm