9

I'm trying to call docker commands via remote api.

Docker remote api does not seem to have 'Detached mode' option. http://docs.docker.io/en/latest/commandline/command/run/

I could use this app in the bash, and I would like to use this via remote api. https://github.com/grigio/docker-stringer

user966151
  • 235
  • 1
  • 5
  • 10

3 Answers3

8

Indeed, the remote API does not have a 'detach' mode as the 'attach' mode is an extra endpoint.

If you want to run in detach mode with the remote API, simply create and start your container without attaching to it.

If the container still shuts down immediately, use docker logs <container id> to check for errors. The problem might have nothing to do with detach.

Gili
  • 86,244
  • 97
  • 390
  • 689
creack
  • 116,210
  • 12
  • 97
  • 73
  • Hi creack, really appreciate your input on this. I tried this but the container starts and stops soon after. When I use the docker client I could avoid the container being stopped by adding option -t (tty). Appreciate any thoughts on this. – imesh Jun 04 '14 at 15:31
  • doh. but it seems like this is not equivalent. using docker run -d will result in the process to stay open and run but using the remote api /container/ID/start will start the container and terminate. – omni Jun 29 '14 at 01:14
6

It's important to understand the "docker run" command encapsulates a series of commands from an API perspective:

  • pull image (if not available locally)
  • create the container
  • attach to the container
  • starts the container

While "docker run -d" is the same thing as above but without the "attach" step.

Therefore, you need to create and then start your container when using the remote API.

If the container still shuts down immediately, use docker logs <container id> to check for errors. The problem might have nothing to do with detach.

Gili
  • 86,244
  • 97
  • 390
  • 689
juliaaano
  • 1,307
  • 1
  • 13
  • 11
1

As far as I can tell, the remote API equivalent of the -i CLI option is "OpenStdin": true in the call to /containers/create. Without this it seems that anything reading from stdin receives EOT.

This is where stdin is initialized (or not initialized) as a pipe to the container, I haven't tracked it down past that.

Kevan Ahlquist
  • 5,375
  • 1
  • 17
  • 25