docker-compose up正在启动容器并立即停止它们 [英] docker-compose up is starting the container and immediately stopping them

查看:293
本文介绍了docker-compose up正在启动容器并立即停止它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker-compose构建服务,但是使用docker-compose启动的容器由于撰写脚本结束而立即停止。但是当我使用docker run为相同的服务映像创建容器时,它正在工作。

I am trying to build services using docker-compose but containers started using docker-compose is stopping immediately as compose script is over. But when i am creating container using docker run for the same service image it is working.

这是我的撰写脚本:

version: '2.1'

networks:
 composetestnetwork:
  driver: bridge
   ipam:
    driver: default
    config:
     - subnet: 172.19.0.0/16
       gateway: 172.19.0.1

services:
 composetestdb:
  build:
   context: .
   dockerfile: Dockerfile-testdb
  cap_add:
   - ALL
  container_name: my-db-compose-container
  labels:
   db.description: "This is a test db"
  volumes:
   - c:/Users:/data
  networks:
   composetestnetwork:
    ipv4_address: 172.19.0.5
  ports:
   - "3306:3306"
  command: 'bash'

可以做什么

推荐答案

如果您使用 bash 作为命令,但没有终端,它将立即退出。这是因为bash启动时,如果没有连接终端,并且没有脚本或其他命令要执行,则它无事可做,因此退出(根据设计)。

If you use bash as the command, but without a terminal, it will exit immediately. This is because when bash starts up, if there is no terminal attached, and it has no script or other command to execute, it has nothing to do, so it exits (by design).

您可以使用其他命令,也可以在终端上附加 tty:true 该服务的定义。

You can either use a different command, or attach a terminal with tty: true as part of the definition of this service.

services:
  composetestdb:
    tty: true
    ...

这篇关于docker-compose up正在启动容器并立即停止它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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