gpt4 book ai didi

linux - centos7容器不断重启

转载 作者:太空宇宙 更新时间:2023-11-04 04:55:17 24 4
gpt4 key购买 nike

我正在尝试使用以下 Docker compose 文件和 Dockerfile 运行 centos7 容器-

version: "2"    data:
build:
context: ./docker-build
dockerfile: Dockerfile.data
restart: always
ports:
- "8082:8082"
command: bash

Dockerfile:

FROM centos:7
RUN yum -y update
CMD /bin/sh

容器不断重启,我不知道原因,如何解决这个问题?

最佳答案

一旦主进程退出,容器就会停止。就您而言,主进程是 shell(/bin/shbash)。没有附加 TTY 的 shell 会立即退出。

如果您想让容器保持运行,请向容器添加 TTY;

使用docker run时;

以交互方式运行容器;

docker run -it centos:7 bash

在后台运行容器(“分离”,-d);

docker run -dit centos:7 bash

使用docker-compose.yml时:

version: "2"
services:
data:
build:
context: ./docker-build
dockerfile: Dockerfile.data
restart: always
ports:
- "8082:8082"
command: bash
tty: true

关于linux - centos7容器不断重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com