[英]How run image as daemon in ruby docker-api?
你不需要做任何特別的事情。 在 API 級別, docker run
做了三件事:
您鏈接到的 GitHub 項目有一些相當復雜的示例。 (Its API documentation doesn't say a whole lot beyond that; for example the Docker::Container docs mostly just list the methods without explaining what could go into the various hash parameters.) If you create and start the container, but don' t附加到它,它將具有與“在后台”運行容器的docker run -d
相同的效果。
# Lifted from https://github.com/swipely/docker-api
# Create a Container.
container = Docker::Container.create('Cmd' => ['ls'], 'Image' => 'base')
# Start running the Container.
container.start
# It is "in the background", unless you specifically #attach to it or
# #wait for it.
我找到解決方案:
container = Docker::Container.create('Cmd' => ["tail", "-f", "/dev/null"], 'Image' => 'some_image')
container.start
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08564fe29591 some_image "tail -f /dev/null" 20 seconds ago Up 10 seconds nervous_ardinghelli
容器啟動后未退出,可以在這個容器中執行!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.