我一直在浏览这里链接的用户指南:
Docker User Guide: Containers。
我在docker终端中运行了以下命令:
$ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
应该创建一个在后台运行的容器。但是,当我查看并查看它是否正在运行时,请使用:
$ docker ps -a
它显示容器已创建但已停止运行。
容器的日志包含以下内容:
true;: 1: true;: Syntax error: end of file unexpected
在不尝试创建守护程序的情况下运行命令会产生类似的结果:
$ docker run ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
true;: 1: true;: Syntax error: end of file unexpected
我猜我的脚本中有语法错误,但是我没有看到它。任何建议表示赞赏。
(This问题有些相似,可能是相关的)。
编辑一些其他信息:我正在Windows 7中使用Docker Quickstart Terminal运行Docker
EDIT2下面接受的答案对我有用,除了我必须在许多命令后附加“默认”以指定我正在与默认计算机对话。
最佳答案
尝试使用单引号:
docker run -d ubuntu:14.04 /bin/sh -c 'while true; do echo hello world; sleep 1; done'
注意:作为mentioned here:When I try to use VirtualBox's console there is all fine.
But it always fail in windows's console (using Docker Quickstart Terminal).
I think the problem is about the end-of-line code (
\n
,\r
or\r\n
).
因此,请尝试先SSH到docker机器(
docker-machine ssh $(docker-machine ip <machine_name>)
),然后再试一次。对于最近创建了机器“
default
”的docker-machine,您甚至不必键入任何内容(在这里,我使用dm
作为docker-machine
的别名):然后,该命令可以使用单引号或双引号:
关于shell - Docker教程: Daemonized Container Closes - Syntax Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35027608/