Docker:用于运行Docker Image的Echo to Terminal

时间:2014-12-03 23:58:29

标签: docker dockerfile

是否有一种方法可以在发出docker run命令的终端中显示echo。如果不使用-d选项,则此处仅显示echo。我可以使用docker日志来查看这些回声,但是我想知道是否有办法直接在发出run命令的终端中显示它们?

Dockerfile:

# Generic Docker Image for Running Node app from Git Repository
FROM    node:0.10.33-slim
ENV NODE_ENV production

# Add script to pull Node app from Git and run the app
COPY docker-node-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE  8080
CMD ["--help"]

入口点脚本:

#!/bin/bash
set -e
# Run the command passed in if it isn't to start a node app
if [ "$1" != 'node-server' ]; then
   exec "$@"
fi
# Logic for pulling the node app and starting it
cd /usr/src
# try to remove the repo if it already exists
rm -rf node-app; true
echo "Pulling Node app's source from $2"
git clone $2 node-app
cd node-app
# Check if we should be running a specific commit from the git repo
if [ ! -z "$3" ]; then
  echo "Changing to commit $3"
  git checkout $3
fi
npm install
echo "Starting the app"
exec node .

1 个答案:

答案 0 :(得分:1)

您可以使用-d或stdout,但不能同时使用两者。如果你想在stdout后台运行容器,你可以使用&

$ docker run ubuntu echo "Stdout from container" &
[1] 2751
$ Stdout from container

或者您可以使用-d和docker logs -f