# Create an exec instance


[API catalog](/reference/api/) · [Docker Engine overview](/reference/api/engine/version/v1.57/) · [Product manual](https://docs.docker.com/engine/) · [OpenAPI specification](/reference/api/engine/version/v1.57.yaml)

API version: 1.57





`POST /containers/{id}/exec`

Run a command inside a running container.

## Connection and access

[API connection and authentication guidance](/reference/api/engine/version/v1.57/#connection)


Server: `/v1.57`

Effective security: alternatives are OR; schemes within an alternative are AND. An empty array declares no HTTP authentication requirement.

```json
null
```

## Example request

Replace placeholders and provide the required credentials or request body.

```console
curl \
  --request POST \
  --unix-socket "${DOCKER_SOCKET:-/var/run/docker.sock}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "AttachStderr": true,
  "AttachStdin": false,
  "AttachStdout": true,
  "Cmd": [
    "date"
  ],
  "DetachKeys": "ctrl-p,ctrl-q",
  "Env": [
    "FOO=bar",
    "BAZ=quux"
  ],
  "Tty": false
}' \
  'http://localhost/v1.57/containers/<ID>/exec'
```



## Parameters

### id

Location: path. Required: yes.

ID or name of container

```json
{
  "description": "ID or name of container",
  "in": "path",
  "name": "id",
  "pointer": "/paths/~1containers~1{id}~1exec/post/parameters/0",
  "required": true,
  "schema": {
    "type": "string"
  }
}
```

## Request and responses

### Request  application/json

Exec configuration


Schema:

```json
{
  "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:
```json
{
  "AttachStderr": true,
  "AttachStdin": false,
  "AttachStdout": true,
  "Cmd": [
    "date"
  ],
  "DetachKeys": "ctrl-p,ctrl-q",
  "Env": [
    "FOO=bar",
    "BAZ=quux"
  ],
  "Tty": false
}
```


### Response 201 application/json

no error


Schema:

```json
{
  "$ref": "#/components/schemas/IDResponse"
}
```










### Response 404 application/json

no such container


Schema:

```json
{
  "$ref": "#/components/schemas/ErrorResponse"
}
```









Example:
```json
{
  "message": "No such container: c2ada9df5af8"
}
```


### Response 409 application/json

container is paused


Schema:

```json
{
  "$ref": "#/components/schemas/ErrorResponse"
}
```









Schema example:
```json
{
  "message": "Something went wrong."
}
```


### Response 500 application/json

Server error


Schema:

```json
{
  "$ref": "#/components/schemas/ErrorResponse"
}
```









Schema example:
```json
{
  "message": "Something went wrong."
}
```


## Complete operation contract

```json
{
  "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"
  ]
}
```

## Referenced schemas

- [#/components/schemas/ErrorResponse](/reference/api/engine/version/v1.57/schemas/ErrorResponse/)

- [#/components/schemas/IDResponse](/reference/api/engine/version/v1.57/schemas/IDResponse/)




