可以与docker-compose一起运行HTTP服务器吗?

时间:2020-08-07 19:17:32

标签: docker docker-compose

我想创建隔离的环境以在其中运行修改后的python解释器。 我有docker-compose.yaml:

version: '3.5'
services:
    cpython:
        image: ubuntu
        ports:
            - "7777:7777"
        volumes:
            - /home/myuser/workspace/cpython:/docker
        working_dir: /docker
        # stdin_open: true
        # tty: true
        command: /docker/python /docker/Tools/scripts/pydoc3 -p 7777

但是启动docker-compose up时我得到了:

myuser@myuser-laptop:~/workspace/cpython$ docker-compose up
Recreating cpython_cpython_1 ... 
Recreating cpython_cpython_1 ... done
Attaching to cpython_cpython_1
cpython_1  | Server ready at http://localhost:7777/
cpython_1  | Server commands: [b]rowser, [q]uit
cpython_1  | server> 
cpython_1  | Server stopped
cpython_cpython_1 exited with code 0

为什么命令/docker/python /docker/Tools/scripts/pydoc3 -p 7777被停止了?在我的主机终端中,它工作正常。

1 个答案:

答案 0 :(得分:1)

好像没有打开交互式终端。试试:

docker run -it -p 7777:7777 -v /home/myuser/workspace/cpython:/docker ubuntu /docker/python /docker/Tools/scripts/pydoc3 -p 7777