Docker撰写分离模式不起作用 [英] Docker compose detached mode not working

查看:37
本文介绍了Docker撰写分离模式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问如何在分离模式下运行docker-compose

Q. How to run docker-compose in detach mode

我正在尝试以分离模式运行docker-compose,但 将在运行后退出 ,但是我可以使用'docker在分离模式下运行相同的映像运行"命令.

I am trying to run docker-compose in detach mode but it will exits after just it's run, but I am able run same image in detach mode using 'docker run' command.

  • 使用"docker run"命令运行图像(以分离模式运行)

docker run -itd ubuntu:16.04

下面是'docker ps -a'命令的输出

below is output of 'docker ps -a' command

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
d84edc987359        ubuntu:16.04        "/bin/bash"         4 seconds ago       Up 3 seconds                                   romantic_albattani

  • 使用'docker-compose up -d'命令运行同一映像(在分离模式下不起作用)

    下面是我的docker-compose.yml文件

    below is my docker-compose.yml file

    version: '3'
    services:
    ubuntu:
        image: ubuntu:16.04
    

    'docker-compose ps'命令输出

    'docker-compose ps' command output

             Name              Command    State    Ports 
    ----------------------------------------------------
    composetesting_ubuntu_1   /bin/bash   Exit 0 
    

  • 更新:如下所示,在docker-compose.yml文件中使用tty:true参数时

    Update: When using tty: true parameter in docker-compose.yml file as below

    version: '3'
    services:
    ubuntu:
        image: ubuntu:16.04
        tty: true
    

    然后控制台将不执行任何命令,就像我键入'ls -l'一样,命令控制台将不响应.

    then console will not execute any command, like if I type 'ls -l' command console will not responding.

    推荐答案

    我只需要在我的docker-compose.yml中添加tty:true

    I just had to add tty: true to my docker-compose.yml

        version: '2'
        services: 
          ubuntu:
            image: ubuntu:16.04
            tty: true 
    

    Docker版本1.12.5,内部版本7392c3b

    Docker version 1.12.5, build 7392c3b

    docker-compose版本1.7.1,内部版本0a9ab35

    docker-compose version 1.7.1, build 0a9ab35

    这篇关于Docker撰写分离模式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆