Docker已启动但无法访问端口8000的localhost

时间:2018-02-19 20:04:13

标签: ubuntu docker nginx

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

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

enter image description here

看起来好像一切都正常运行但是如果我在8000端口访问localhost,我会看到以下屏幕:

enter image description here

我正在使用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(没有portnumber),它会显示我的nginx已正确安装(默认的nginx屏幕)

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

1 个答案:

答案 0 :(得分: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

相关问题