# Create a secret


[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 /secrets/create`



## 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-binary @request-body \
  'http://localhost/v1.57/secrets/create'
```


Prepare request-body using the selected media type and schema.


## Parameters

## Request and responses

### Request  application/json




Schema:

```json
{
  "allOf": [
    {
      "$ref": "#/components/schemas/SecretSpec"
    },
    {
      "example": {
        "Data": "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==",
        "Driver": {
          "Name": "secret-bucket",
          "Options": {
            "OptionA": "value for driver option A",
            "OptionB": "value for driver option B"
          }
        },
        "Labels": {
          "foo": "bar"
        },
        "Name": "app-key.crt"
      },
      "type": "object"
    }
  ]
}
```










### Response 201 application/json

no error


Schema:

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










### Response 409 application/json

name conflicts with an existing object


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."
}
```


### Response 503 application/json

node is not part of a swarm


Schema:

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









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


## Complete operation contract

```json
{
  "operationId": "SecretCreate",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "allOf": [
            {
              "$ref": "#/components/schemas/SecretSpec"
            },
            {
              "example": {
                "Data": "VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==",
                "Driver": {
                  "Name": "secret-bucket",
                  "Options": {
                    "OptionA": "value for driver option A",
                    "OptionB": "value for driver option B"
                  }
                },
                "Labels": {
                  "foo": "bar"
                },
                "Name": "app-key.crt"
              },
              "type": "object"
            }
          ]
        }
      }
    },
    "x-codegen-request-body-name": "body"
  },
  "responses": {
    "201": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/IDResponse"
          }
        }
      },
      "description": "no error"
    },
    "409": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "name conflicts with an existing object"
    },
    "500": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "server error"
    },
    "503": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/ErrorResponse"
          }
        }
      },
      "description": "node is not part of a swarm"
    }
  },
  "summary": "Create a secret",
  "tags": [
    "Secret"
  ]
}
```

## Referenced schemas

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

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

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




