2

我创建了我的第一个 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
4

1 回答 1

5

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

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

于 2016-09-19T19:17:49.670 回答