Docker图像不会在后台运行
我创build了我的第一个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
使用bash
入口点,bdin会在stdin返回文件结尾时立即退出。 所以你离开它,你需要用docker run -itd image-name
来启动它。 -i
使其交互, -t
指定一个tty, -d
分离。 这使stdin在容器上保持打开状态,并允许您对容器附加或执行命令。
后续:我刚刚看到你的命令 – --port 81
,当作为命令运行在bash
会给你一个无效的选项。 如果你需要运行mongo作为选项,你需要一个不同的入口点。