![](/img/trans.png)
[英]Can't access Docker container on exposed port from anywhere even localhost
[英]Docker has is up however can't reach localhost at port 8000
所以我正在嘗試設置我的應用程序。
我運行命令sudo docker-compose ps
我得到以下輸出
看起來好像一切正常並且正在運行,但是如果我在端口8000進入localhost,則會顯示以下屏幕:
我正在使用nginx
,這是我的配置:
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
請注意,如果我轉到本地主機(沒有端口號),則表明我的nginx已正確安裝(默認nginx屏幕)
誰能告訴我我想念的東西嗎?
您需要將端口從主機映射到正在運行的容器。
docker run -d -p 5801:5801 -p 5802:5802 .....
另外,如果您的工作站/筆記本電腦有多個網卡,請確保將其映射到您要嘗試從其訪問的正確網卡:
docker run -d -p <interface IP>:<outside port>:<inside port> .....
請參閱本文以獲取更多信息: https : //forums.docker.com/t/how-to-expose-port-on-running-container/3252/5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.