簡體   English   中英

如何在 ruby docker-api 中將映像作為守護進程運行?

[英]How run image as daemon in ruby docker-api?

我需要docker-api方法,它允許我將圖像作為守護進程運行。

Docker 命令供參考: docker run -t -d some_image

有誰知道解決方案?

你不需要做任何特別的事情。 在 API 級別, docker run做了三件事:

  1. 它使用您指定的大多數選項創建一個新容器
  2. 啟動容器
  3. 附加到容器的 stdin 和 stdout

您鏈接到的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM