我正在尝试使用以下命令运行 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。
最佳答案
没有回应似乎很正常,因为以下两点:
docker run --name mycontainer -p 8080:80 nginx
顺便说一句,最好运行:docker run --rm -p 8080:80 nginx
考虑到 正在运行的容器是短暂的 ,并且可以在停止时自动删除,这要归功于 --rm
选项(因此将其命名为 --name …
是不必要的),然后在以后重新创建而不会丢失数据,因为持久数据通常存储在所谓的 Docker volumes 中.https://
开头但通常情况下,如果容器不涉及专用的 TLS 反向代理配置,则它只接受 HTTP 请求(以 http://
开头)是正常的;因此,您应该尝试浏览以下 URL:http://localhost:8080
但是,如果您特别有兴趣为您的 dockerized 网站提供一些 HTTPS 支持,请参阅例如this StackOverflow question或 browse other questions involving these tags .
关于Docker:8080 没有从 nginx 容器中得到响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68687625/