简体   繁体   中英

How run image as daemon in ruby docker-api?

i'm need docker-api method that will allow me to run image as daemon.

Docker command for reference: docker run -t -d some_image

Does anyone know a solution?

You don't need to do anything special. At an API level, docker run does three things:

  1. It creates a new container with most of the options you specify;
  2. It starts the container ; and
  3. It attaches to the containers's stdin and stdout .

The GitHub project you link to has some fairly intricate examples. (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 attach to it, it will have the same effect of docker run -d of running the container "in the background".

# 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.

I find solution:

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

Container not Exited after start, and you can make exec in this container!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM