Search or ask Docker

Create an exec instance

POST /containers/{id}/exec — Docker Engine API 1.57.

View Markdown
POST/containers/{id}/exec
Run a command inside a running container.

Connection and access

API connection and authentication guidance

/v1.57

No HTTP authentication requirement is declared for this operation. Transport access controls can still apply.

Parameters

id path Required

ID or name of container

Type: string

All schema constraints and annotations
{
  "type": "string"
}

Request and responses

Request

Exec configuration

application/json

Type: object

AttachStderr

Type: boolean

Attach to stderr of the exec command.
All schema constraints and annotations
{
  "description": "Attach to `stderr` of the exec command.",
  "type": "boolean"
}
AttachStdin

Type: boolean

Attach to stdin of the exec command.
All schema constraints and annotations
{
  "description": "Attach to `stdin` of the exec command.",
  "type": "boolean"
}
AttachStdout

Type: boolean

Attach to stdout of the exec command.
All schema constraints and annotations
{
  "description": "Attach to `stdout` of the exec command.",
  "type": "boolean"
}
Cmd

Type: array

Command to run, as a string or array of strings.
Array item

Type: string

All schema constraints and annotations
{
  "type": "string"
}
All schema constraints and annotations
{
  "description": "Command to run, as a string or array of strings.",
  "items": {
    "type": "string"
  },
  "type": "array"
}
ConsoleSize

Type: array

Initial console size, as an [height, width] array.
Array item

Type: integer

All schema constraints and annotations
{
  "minimum": 0,
  "type": "integer"
}
All schema constraints and annotations
{
  "description": "Initial console size, as an `[height, width]` array.",
  "example": [
    80,
    64
  ],
  "items": {
    "minimum": 0,
    "type": "integer"
  },
  "maxItems": 2,
  "minItems": 2,
  "type": "array",
  "x-nullable": true
}
DetachKeys

Type: string

Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.
All schema constraints and annotations
{
  "description": "Override the key sequence for detaching a container. Format is\na single character `[a-Z]` or `ctrl-\u003cvalue\u003e` where `\u003cvalue\u003e`\nis one of: `a-z`, `@`, `^`, `[`, `,` or `_`.\n",
  "type": "string"
}
Env

Type: array

A list of environment variables in the form ["VAR=value", ...].
Array item

Type: string

All schema constraints and annotations
{
  "type": "string"
}
All schema constraints and annotations
{
  "description": "A list of environment variables in the form `[\"VAR=value\", ...]`.\n",
  "items": {
    "type": "string"
  },
  "type": "array"
}
Privileged

Type: boolean

Runs the exec process with extended privileges.
All schema constraints and annotations
{
  "default": false,
  "description": "Runs the exec process with extended privileges.",
  "type": "boolean"
}
Tty

Type: boolean

Allocate a pseudo-TTY.
All schema constraints and annotations
{
  "description": "Allocate a pseudo-TTY.",
  "type": "boolean"
}
User

Type: string

The user, and optionally, group to run the exec process inside the container. Format is one of: user, user:group, uid, or uid:gid.
All schema constraints and annotations
{
  "description": "The user, and optionally, group to run the exec process inside\nthe container. Format is one of: `user`, `user:group`, `uid`,\nor `uid:gid`.\n",
  "type": "string"
}
WorkingDir

Type: string

The working directory for the exec process inside the container.
All schema constraints and annotations
{
  "description": "The working directory for the exec process inside the container.\n",
  "type": "string"
}
All schema constraints and annotations
{
  "example": {
    "AttachStderr": true,
    "AttachStdin": false,
    "AttachStdout": true,
    "Cmd": [
      "date"
    ],
    "DetachKeys": "ctrl-p,ctrl-q",
    "Env": [
      "FOO=bar",
      "BAZ=quux"
    ],
    "Tty": false
  },
  "properties": {
    "AttachStderr": {
      "description": "Attach to `stderr` of the exec command.",
      "type": "boolean"
    },
    "AttachStdin": {
      "description": "Attach to `stdin` of the exec command.",
      "type": "boolean"
    },
    "AttachStdout": {
      "description": "Attach to `stdout` of the exec command.",
      "type": "boolean"
    },
    "Cmd": {
      "description": "Command to run, as a string or array of strings.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "ConsoleSize": {
      "description": "Initial console size, as an `[height, width]` array.",
      "example": [
        80,
        64
      ],
      "items": {
        "minimum": 0,
        "type": "integer"
      },
      "maxItems": 2,
      "minItems": 2,
      "type": "array",
      "x-nullable": true
    },
    "DetachKeys": {
      "description": "Override the key sequence for detaching a container. Format is\na single character `[a-Z]` or `ctrl-\u003cvalue\u003e` where `\u003cvalue\u003e`\nis one of: `a-z`, `@`, `^`, `[`, `,` or `_`.\n",
      "type": "string"
    },
    "Env": {
      "description": "A list of environment variables in the form `[\"VAR=value\", ...]`.\n",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "Privileged": {
      "default": false,
      "description": "Runs the exec process with extended privileges.",
      "type": "boolean"
    },
    "Tty": {
      "description": "Allocate a pseudo-TTY.",
      "type": "boolean"
    },
    "User": {
      "description": "The user, and optionally, group to run the exec process inside\nthe container. Format is one of: `user`, `user:group`, `uid`,\nor `uid:gid`.\n",
      "type": "string"
    },
    "WorkingDir": {
      "description": "The working directory for the exec process inside the container.\n",
      "type": "string"
    }
  },
  "title": "ExecConfig",
  "type": "object"
}

Schema example

{
  "AttachStderr": true,
  "AttachStdin": false,
  "AttachStdout": true,
  "Cmd": [
    "date"
  ],
  "DetachKeys": "ctrl-p,ctrl-q",
  "Env": [
    "FOO=bar",
    "BAZ=quux"
  ],
  "Tty": false
}

Response 201

no error

application/json

Schema: IDResponse

Response 404

no such container

application/json

Schema: ErrorResponse

Example

{
  "message": "No such container: c2ada9df5af8"
}

Response 409

container is paused

application/json

Schema: ErrorResponse

Schema example

{
  "message": "Something went wrong."
}

Response 500

Server error

application/json

Schema: ErrorResponse

Schema example

{
  "message": "Something went wrong."
}

Referenced schemas

#/components/schemas/ErrorResponse

#/components/schemas/IDResponse

Complete operation contract
{
  "description": "Run a command inside a running container.",
  "operationId": "ContainerExec",
  "parameters": [
    {
      "description": "ID or name of container",
      "in": "path",
      "name": "id",
      "required": true,
      "schema": {
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "example": {
            "AttachStderr": true,
            "AttachStdin": false,
            "AttachStdout": true,
            "Cmd": [
              "date"
            ],
            "DetachKeys": "ctrl-p,ctrl-q",
            "Env": [
              "FOO=bar",
              "BAZ=quux"
            ],
            "Tty": false
          },
          "properties": {
            "AttachStderr": {
              "description": "Attach to `stderr` of the exec command.",
              "type": "boolean"
            },
            "AttachStdin": {
              "description": "Attach to `stdin` of the exec command.",
              "type": "boolean"
            },
            "AttachStdout": {
              "description": "Attach to `stdout` of the exec command.",
              "type": "boolean"
            },
            "Cmd": {
              "description": "Command to run, as a string or array of strings.",
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            "ConsoleSize": {
              "description": "Initial console size, as an `[height, width]` array.",
              "example": [
                80,
                64
              ],
              "items": {
                "minimum": 0,
                "type": "integer"
              },
              "maxItems": 2,
              "minItems": 2,
              "type": "array",
              "x-nullable": true
            },
            "DetachKeys": {
              "description": "Override the key sequence for detaching a container. Format is\na single character `[a-Z]` or `ctrl-\u003cvalue\u003e` where `\u003cvalue\u003e`\nis one of: `a-z`, `@`, `^`, `[`, `,` or `_`.\n",
              "type": "string"
            },
            "Env": {
              "description": "A list of environment variables in the form `[\"VAR=value\", ...]`.\n",
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            "Privileged": {
              "default": false,
              "description": "Runs the exec process with extended privileges.",
              "type": "boolean"
            },
            "Tty": {
              "description": "Allocate a pseudo-TTY.",
              "type": "boolean"
            },
            "User": {
              "description": "The user, and optionally, group to run the exec process inside\nthe container. Format is one of: `user`, `user:group`, `uid`,\nor `uid:gid`.\n",
              "type": "string"
            },
            "WorkingDir": {
              "description": "The working directory for the exec process inside the container.\n",
              "type": "string"
            }
          },
          "title": "ExecConfig",
          "type": "object"
        }
      }
    },
    "description": "Exec configuration",
    "required": true,
    "x-codegen-request-body-name": "execConfig"
  },
  "responses": {
    "201": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/IDResponse"
          }
        }
      },
      "description": "no error"
    },
    "404": {
      "content": {
        "application/json": {
          "example": {
            "message": "No such container: c2ada9df5af8"
          },
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "no such container"
    },
    "409": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "container is paused"
    },
    "500": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "Server error"
    }
  },
  "summary": "Create an exec instance",
  "tags": [
    "Exec"
  ]
}