docker run command hangs until the container stops

时间:2018-09-18 19:36:29

标签: docker

I am trying to run a PPTP VPN server in a Docker container. but when I do the command docker run pptpserver, or all different container I have tried, It will work but my cursor is just flashing and does not let me do any other command. I tried a super simple one, just copying test.sh in the container and run it, and it prints a confined times test, but I want a container that's in the background.

test.sh:
#/bin/bash
while :; do
  echo "test"
  sleep 2
done

The only way I can stop it is to stop the container in another terminal. Is there something I can do to just run a container like it shouts do, in the background.

# docker version
Client:
 Version:   17.12.1-ce
 API version:   1.35
 Go version:    go1.10.1
 Git commit:    7390fc6
 Built: Wed Apr 18 01:23:11 2018
 OS/Arch:   linux/amd64

Server:
 Engine:
  Version:  17.12.1-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.10.1
  Git commit:   7390fc6
  Built:    Wed Feb 28 17:46:05 2018
  OS/Arch:  linux/amd64
  Experimental: false

1 个答案:

答案 0 :(得分:0)

为防止这种情况,您应该通过指定-d=true或仅使用-d选项以分离模式启动容器。如果未指定,则docker默认为前台模式,它将控制台附加到容器的标准输入,输出和标准错误中的进程,使其看起来好像您的终端在“挂起”。

所以尝试:

  

docker run -d pptpserver

您可以在Docker Run Reference文档中了解有关此行为的更多信息。