【问题标题】:Docker has is up however can't reach localhost at port 8000Docker 已启动,但无法在端口 8000 访问 localhost
【发布时间】:2018-02-20 05:02:34
【问题描述】:

所以我正在尝试设置我的应用程序。

我运行命令sudo docker-compose ps 我得到以下输出

看起来一切都已启动并正在运行,但是如果我在端口 8000 访问本地主机,我会看到以下屏幕:

我正在使用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;
#   }
#}

请注意,如果我转到 localhost(没有端口号),它表明我的 nginx 已正确安装(默认 nginx 屏幕)

谁能告诉我我错过了什么?

【问题讨论】:

  • 您是否尝试过通过:127.0.0.1:8080 访问,另外,看起来端口 8000 并没有映射到主机端口。

标签: ubuntu docker nginx


【解决方案1】:

您需要将主机的端口映射到正在运行的容器。

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

【讨论】:

    猜你喜欢
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 2020-09-30
    • 1970-01-01
    相关资源
    最近更新 更多