Method: Docker::Compose::Session#run

Defined in:
lib/docker/compose/session.rb

#run(service, *cmd, detached: false, no_deps: false, volumes: [], env: [], rm: false, no_tty: false, user: nil, service_ports: false) ⇒ Object

Idempotently run an arbitrary command with a service container.

Parameters:

  • service (String)

    name to run

  • cmd (String)

    command statement to run

  • detached (Boolean) (defaults to: false)

    if true, to start services in the background; otherwise, monitor logs in the foreground and shutdown on Ctrl+C

  • no_deps (Boolean) (defaults to: false)

    if true, just run specified services without running the services that they depend on

  • env (Array) (defaults to: [])

    a list of environment variables (see: -e flag)

  • volumes (Array) (defaults to: [])

    a list of volumes to bind mount (see: -v flag)

  • rm (Boolean) (defaults to: false)

    remove the container when done

  • no_tty (Boolean) (defaults to: false)

    disable pseudo-tty allocation (see: -T flag)

  • user (String) (defaults to: nil)

    run as specified username or uid (see: -u flag)

Raises:

  • (Error)

    if command fails



140
141
142
143
144
145
# File 'lib/docker/compose/session.rb', line 140

def run(service, *cmd, detached: false, no_deps: false, volumes: [], env: [], rm: false, no_tty: false, user: nil, service_ports: false)
  o = opts(d: [detached, false], no_deps: [no_deps, false], rm: [rm, false], T: [no_tty, false], u: [user, nil], service_ports: [service_ports, false])
  env_params = env.map { |v| { e: v } }
  volume_params = volumes.map { |v| { v: v } }
  run!('run', o, *env_params, *volume_params, service, cmd)
end