我正在编写一个dockerfile,在其中我基于alpine:3.9
docker映像运行服务器应用程序。我通过运行应用程序并通过GET
发送curl
请求来测试我的应用程序是否正确安装。
我发送请求,直到得到答案。因此,万一遇到麻烦,我想使用内置的timeout
函数使测试超时。
我在debian上使用docker version 19.03.4, build 9013bf583a
。>>
命令:
docker run --rm -it alpine:3.9 timeout -t 2 /bin/sh -c 'sleep 5; echo "Not to be seen..."'
退出显示
Not to be seen...
。
如果我以这种方式使用超时,则超时似乎被忽略了……如果将其放入docker文件中,则会遇到相同的问题。
FROM alpine:3.9 RUN timeout -t 2 /bin/sh -c 'sleep 5; echo "Not to be seen..."'
docker build -t test . Sending build context to Docker daemon 2.048kB Step 1/2 : FROM alpine:3.9 ---> 055936d39205 Step 2/2 : RUN timeout -t 2 /bin/sh -c 'sleep 5; echo "Not to be seen..."' ---> Running in 0fa22cd02173 Not to be seen... Removing intermediate container 0fa22cd02173 ---> e88107c3811b Successfully built e88107c3811b Successfully tagged test:latest
我们可以看到控制台中显示的
Not to be seen...
。
如何解决此问题?
我测试了多件事,并且超时功能运行良好。在dockerfile中使用它或在docker run
函数中传递它时应该有问题...
当我尝试:
docker run --rm -it alpine:3.9 /bin/sh # Then in container timeout -t 2 /bin/sh -c 'sleep 5; echo "Not to be seen..."'
以状态码143退出。并显示
Terminated
。
当我尝试:
docker run --rm --name test -td alpine:3.9 /bin/sh docker exec -it test timeout -t 2 /bin/sh -c 'sleep 5; echo "Not to be seen..."'
退出,状态码为143。未按预期显示任何内容。
上下文我正在编写一个dockerfile,我在其中运行基于alpine:3.9 docker image的服务器应用程序。我通过运行应用程序并发送带有curl的GET请求来测试我的应用程序是否正确安装。 ...
许多程序以PID 1(包括/bin/sh
)运行时会删除默认信号处理程序。