Docker container can not run as a daemon

2020-06-23 07:41发布

I am following Docker's docs to understand how Docker works.

But i meet a problem in that Doc,

The say that when this command is run:

$ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"

a daemon is started because of the -d flag.

But when checking the running container with the docker ps command, it is empty, with just titles:

CONTAINER ID  IMAGE         COMMAND               CREATED        STATUS       PORTS NAMES

Using the docker ps -a command to watch all containers I see this:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
e7f1bebd5a49        ubuntu:14.04        "/bin/sh -c while tru"   6 minutes ago       Exited (2) 4 minutes ago                       cranky_mcclintock

It exits with error code 2. Watching the log:

docker logs e7f1bebd5a49
true;: 1: true;: Syntax error: end of file unexpected

Why is this happening? I am running Docker in Windows 10 (using the Docker Quickstart Terminal).

This is part of my docker info:

Containers: 3
Images: 52
Server Version: 1.9.1
Storage Driver: aufs
    Root Dir: /mnt/sda1/var/lib/docker/aufs
    Backing Filesystem: extfs
    Dirs: 58
    Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.1.13-boot2docker
Operating System: Boot2Docker 1.9.1 (TCL 6.4.1);
CPUs: 1
Total Memory: 996.2 MiB
Name: default
Debug mode (server): true
    File Descriptors: 12
    Goroutines: 20
    EventsListeners: 0
    Init SHA1:
    Init Path: /usr/local/bin/docker
    Docker Root Dir: /mnt/sda1/var/lib/docker
Registry: https://index.docker.io/v1/
Labels:
    provider=virtualbox

Here is the docker events after docker run

$ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
e7f1bebd5a490e35ce8451c5f12a4a4f4e089bd70fc6ad1726e927a0610f3e49

2016-01-14T13:20:55.350098419+08:00 e7f1bebd5a490e35ce8451c5f12a4a4f4e089bd70fc6ad1726e927a0610f3e49: (from ubuntu:14.04) create
2016-01-14T13:20:55.363562836+08:00 e7f1bebd5a490e35ce8451c5f12a4a4f4e089bd70fc6ad1726e927a0610f3e49: (from ubuntu:14.04) start
2016-01-14T13:20:55.436727252+08:00 e7f1bebd5a490e35ce8451c5f12a4a4f4e089bd70fc6ad1726e927a0610f3e49: (from ubuntu:14.04) die

标签: docker
1条回答
够拽才男人
2楼-- · 2020-06-23 08:18

When using VirtualBox's console everything works. It only fails in Windows's console (using the Docker Quickstart Terminal).

I think the underlying problem is with the end-of-line code character (\n,\r or \r\n).

查看更多
登录 后发表回答