AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[cherrypy](server)

Martin Hope
evoelise
Asked: 2022-01-26 03:41:01 +0800 CST

Docker Compose 端口未暴露?

  • 2

我有一个简单的基于 Python 的 Web 服务器,它运行在一个使用 docker compose 设置的容器中,该容器公开了 8080 端口。

当我 docker-compose up 服务时,它报告端口已公开,但端口未对外公开。

接下来我应该看什么诊断?

这是一个典型的运行

➜  demo04 sudo docker-compose up -d
Recreating leagueweb_database ... done
Recreating leagueweb_server   ... done

Python Web 服务器(使用 CherryPy)报告它已启动正常并打开端口 8080。

leagueweb_server | [25/Jan/2022:11:27:21] ENGINE Serving on http://127.0.0.1:8080

Docker 报告它正在转发端口 8080

➜  demo04 sudo docker-compose ps
       Name                     Command                  State                              Ports
------------------------------------------------------------------------------------------------------------------------
leagueweb_database   /entrypoint.sh mysqld            Up (healthy)   0.0.0.0:3306->3306/tcp,:::3306->3306/tcp, 33060/tcp
leagueweb_server     ./wait-for-it.sh database: ...   Up             0.0.0.0:8080->8080/tcp,:::8080->8080/tcp

从远程 PC 测试这个我可以看到,虽然端口 3306 是外部开放的 - 端口 8080 不是。

PS C:> Test-NetConnection 192.168.1.132 -Port 3306
RemoteAddress    : 192.168.1.132
RemotePort       : 3306
TcpTestSucceeded : True

PS C:> Test-NetConnection 192.168.1.132 -Port 8080
WARNING: TCP connect to (192.168.1.132 : 8080) failed

防火墙已关闭

➜  demo04 sudo ufw status
Status: inactive

这是码头工人撰写文件

version: '3'
services:

    leagueweb:
        # Install Python and required libraries with a Dockerfile
        build:
            context: .
            dockerfile: leagueweb.dockerfile
            
        restart: unless-stopped
        
        container_name: leagueweb_server
        
        # Don't start up until the database is started
        depends_on:
            - database
        
        # Expose HTTP port 
        ports:
            - "8080:8080"

        # Mount the leagueweb code and resources
        volumes:
            - "/home/testuser/demo04/code:/leagueweb"
 
        # Start the server only once the database is running
        command: ["./wait-for-it.sh", "database:3306", "--", "python", "-u", "/leagueweb/leagueweb.py"]
        

    database:
        # Use MySQL 5.7 as the database
        image: mysql/mysql-server:5.7
        
        restart: unless-stopped
        
        container_name: leagueweb_database

        # Set environment variables to set initial database set-up
        environment:
            - "MYSQL_ROOT_PASSWORD=root"
            - "MYSQL_USER=leagueweb"
            - "MYSQL_PASSWORD=********"
            - "MYSQL_DATABASE=leagueweb01"
            
        # Uncomment to expose the MySQL database externally on port 3306 for 
        # testing 
        ports:
            - "3306:3306"

        # Mount init.sql file to automatically run and create tables for us.
        # everything in docker-entrypoint-initdb.d folder is executed as 
        # soon as container is up and running.
        volumes:
            - "/home/testuser/demo04/db:/docker-entrypoint-initdb.d"
python docker docker-compose cherrypy
  • 1 个回答
  • 2052 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve