【问题标题】:Docker images wont run in backgroundDocker 图像不会在后台运行
【发布时间】:2017-01-27 13:44:27
【问题描述】:

我创建了我的第一个 Dockerfile,但是当我运行命令时

sudo docker ps

容器没有在后台运行,这是我的 dockerfile:

# Set the base image to Ubuntu
FROM debian:jessie

# File Author / Maintainer
MAINTAINER <Qop>

# Update the repository sources list
RUN apt-get update

################## BEGIN INSTALLATION ######################

RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y \
vim \
apache2

##################### INSTALLATION END #####################

# Expose the default port
EXPOSE 81

# Default port to execute the entrypoint (MongoDB)
CMD ["--port 81"]

# Set default container command
ENTRYPOINT /bin/bash

【问题讨论】:

    标签: docker dockerfile docker-build


    【解决方案1】:

    使用bash 入口点,只要标准输入返回文件结尾,bash 就会退出。所以你让它运行,你需要用docker run -itd image-name启动它。 -i 使其具有交互性,-t 分配一个 tty,-d 分离。这使标准输入在容器上保持打开状态,并允许您对容器附加或执行命令。

    跟进:我刚刚看到你的命令--port 81,当它作为bash 上的命令运行时会给你一个无效的选项。如果您需要使用它作为选项运行 mongo,则需要一个不同的入口点。

    【讨论】:

    • 谢谢,这很有意义!
    猜你喜欢
    • 2021-06-09
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    相关资源
    最近更新 更多