Dockerfile:
FROM shawnzhu/ruby-nodejs:0.12.7 RUN \ apt-get install git \ && npm install -g bower gulp grunt \ gem install sass RUN useradd -ms /bin/bash devel # Deal with ssh COPY ssh_keys/id_rsa /devel/.ssh/id_rsa COPY ssh_keys/id_rsa.pub /devel/.ssh/id_rsa.pub RUN echo "IdentityFile /devel/.ssh/id_rsa" > /devel/.ssh/config # set root password RUN echo 'root:password' | chpasswd # Add gitconfig COPY .gitconfig /devel/.gitconfig USER devel WORKDIR /var/www/ EXPOSE 80
docker-compose.yml文件:
nodejs: build: . ports: - "8001:80" - "3000:3000" volumes: - ~/Web/docker/nodejs/www:/var/www
命令:
$ docker-compose build nodejs
$ docker图片
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE nodejs_nodejs latest aece5fb27134 2 minutes ago 596.5 MB shawnzhu/ruby-nodejs 0.12.7 bbd5b568b88f 5 months ago 547.5 MB
$ docker-compose up -d nodejs
Creating nodejs_nodejs_1
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c24c6d0e756b nodejs_nodejs "/bin/bash" About a minute ago Exited (0) About a minute ago nodejs_nodejs_1
你可以看到docker-compose up -d
应该创建一个容器并在后台运行它,但事实并非如此.而是退出代码0.
如果您的Dockerfile没有做任何事情(例如,要在端口80上侦听的Web服务器),它将在完成指令运行后立即被丢弃.因为Docker容器应该是"短暂的".
如果您只想启动容器并通过终端与其进行交互,请不要使用docker-compose up -d
,请改用以下内容:
docker run -it --entrypoint=/bin/bash [your_image_id]
这将启动您的容器并运行/bin/bash
,-it
帮助您保持终端会话与容器交互.完成工作后,按Ctrl-D
退出.