1. Packages
  2. Docker Provider
  3. API Docs
  4. Secret
Viewing docs for Docker v4.11.2
published on Wednesday, Apr 1, 2026 by Pulumi
 logo
Viewing docs for Docker v4.11.2
published on Wednesday, Apr 1, 2026 by Pulumi

    Manages the secrets of a Docker service in a swarm.

    Example Usage

    Basic

    import * as pulumi from "@pulumi/pulumi";
    import * as docker from "@pulumi/docker";
    import * as std from "@pulumi/std";
    
    const foo = new docker.Secret("foo", {
        name: "foo",
        data: std.index.base64encode({
            input: "{\"foo\": \"s3cr3t\"}",
        }).result,
    });
    
    import pulumi
    import pulumi_docker as docker
    import pulumi_std as std
    
    foo = docker.Secret("foo",
        name="foo",
        data=std.index.base64encode(input="{\"foo\": \"s3cr3t\"}")["result"])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
    	"github.com/pulumi/pulumi-std/sdk/go/std"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		invokeBase64encode, err := std.Base64encode(ctx, map[string]interface{}{
    			"input": "{\"foo\": \"s3cr3t\"}",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = docker.NewSecret(ctx, "foo", &docker.SecretArgs{
    			Name: pulumi.String("foo"),
    			Data: invokeBase64encode.Result,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Docker = Pulumi.Docker;
    using Std = Pulumi.Std;
    
    return await Deployment.RunAsync(() => 
    {
        var foo = new Docker.Secret("foo", new()
        {
            Name = "foo",
            Data = Std.Index.Base64encode.Invoke(new()
            {
                Input = "{\"foo\": \"s3cr3t\"}",
            }).Result,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.docker.Secret;
    import com.pulumi.docker.SecretArgs;
    import com.pulumi.std.StdFunctions;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var foo = new Secret("foo", SecretArgs.builder()
                .name("foo")
                .data(StdFunctions.base64encode(Map.of("input", "{\"foo\": \"s3cr3t\"}")).result())
                .build());
    
        }
    }
    
    resources:
      foo:
        type: docker:Secret
        properties:
          name: foo
          data:
            fn::invoke:
              function: std:base64encode
              arguments:
                input: '{"foo": "s3cr3t"}'
              return: result
    

    Create Secret Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new Secret(name: string, args: SecretArgs, opts?: CustomResourceOptions);
    @overload
    def Secret(resource_name: str,
               args: SecretArgs,
               opts: Optional[ResourceOptions] = None)
    
    @overload
    def Secret(resource_name: str,
               opts: Optional[ResourceOptions] = None,
               data: Optional[str] = None,
               labels: Optional[Sequence[SecretLabelArgs]] = None,
               name: Optional[str] = None)
    func NewSecret(ctx *Context, name string, args SecretArgs, opts ...ResourceOption) (*Secret, error)
    public Secret(string name, SecretArgs args, CustomResourceOptions? opts = null)
    public Secret(String name, SecretArgs args)
    public Secret(String name, SecretArgs args, CustomResourceOptions options)
    
    type: docker:Secret
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args SecretArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args SecretArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args SecretArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args SecretArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args SecretArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var secretResource = new Docker.Index.Secret("secretResource", new()
    {
        Data = "string",
        Labels = new[]
        {
            new Docker.Inputs.SecretLabelArgs
            {
                Label = "string",
                Value = "string",
            },
        },
        Name = "string",
    });
    
    example, err := docker.NewSecret(ctx, "secretResource", &docker.SecretArgs{
    	Data: pulumi.String("string"),
    	Labels: docker.SecretLabelArray{
    		&docker.SecretLabelArgs{
    			Label: pulumi.String("string"),
    			Value: pulumi.String("string"),
    		},
    	},
    	Name: pulumi.String("string"),
    })
    
    var secretResource = new Secret("secretResource", SecretArgs.builder()
        .data("string")
        .labels(SecretLabelArgs.builder()
            .label("string")
            .value("string")
            .build())
        .name("string")
        .build());
    
    secret_resource = docker.Secret("secretResource",
        data="string",
        labels=[{
            "label": "string",
            "value": "string",
        }],
        name="string")
    
    const secretResource = new docker.Secret("secretResource", {
        data: "string",
        labels: [{
            label: "string",
            value: "string",
        }],
        name: "string",
    });
    
    type: docker:Secret
    properties:
        data: string
        labels:
            - label: string
              value: string
        name: string
    

    Secret Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The Secret resource accepts the following input properties:

    Data string
    Base64-url-safe-encoded secret data
    Labels List<SecretLabel>
    User-defined key/value metadata
    Name string
    User-defined name of the secret
    Data string
    Base64-url-safe-encoded secret data
    Labels []SecretLabelArgs
    User-defined key/value metadata
    Name string
    User-defined name of the secret
    data String
    Base64-url-safe-encoded secret data
    labels List<SecretLabel>
    User-defined key/value metadata
    name String
    User-defined name of the secret
    data string
    Base64-url-safe-encoded secret data
    labels SecretLabel[]
    User-defined key/value metadata
    name string
    User-defined name of the secret
    data str
    Base64-url-safe-encoded secret data
    labels Sequence[SecretLabelArgs]
    User-defined key/value metadata
    name str
    User-defined name of the secret
    data String
    Base64-url-safe-encoded secret data
    labels List<Property Map>
    User-defined key/value metadata
    name String
    User-defined name of the secret

    Outputs

    All input properties are implicitly available as output properties. Additionally, the Secret resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing Secret Resource

    Get an existing Secret resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: SecretState, opts?: CustomResourceOptions): Secret
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            data: Optional[str] = None,
            labels: Optional[Sequence[SecretLabelArgs]] = None,
            name: Optional[str] = None) -> Secret
    func GetSecret(ctx *Context, name string, id IDInput, state *SecretState, opts ...ResourceOption) (*Secret, error)
    public static Secret Get(string name, Input<string> id, SecretState? state, CustomResourceOptions? opts = null)
    public static Secret get(String name, Output<String> id, SecretState state, CustomResourceOptions options)
    resources:  _:    type: docker:Secret    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Data string
    Base64-url-safe-encoded secret data
    Labels List<SecretLabel>
    User-defined key/value metadata
    Name string
    User-defined name of the secret
    Data string
    Base64-url-safe-encoded secret data
    Labels []SecretLabelArgs
    User-defined key/value metadata
    Name string
    User-defined name of the secret
    data String
    Base64-url-safe-encoded secret data
    labels List<SecretLabel>
    User-defined key/value metadata
    name String
    User-defined name of the secret
    data string
    Base64-url-safe-encoded secret data
    labels SecretLabel[]
    User-defined key/value metadata
    name string
    User-defined name of the secret
    data str
    Base64-url-safe-encoded secret data
    labels Sequence[SecretLabelArgs]
    User-defined key/value metadata
    name str
    User-defined name of the secret
    data String
    Base64-url-safe-encoded secret data
    labels List<Property Map>
    User-defined key/value metadata
    name String
    User-defined name of the secret

    Supporting Types

    SecretLabel, SecretLabelArgs

    Label string
    Name of the label
    Value string
    Value of the label
    Label string
    Name of the label
    Value string
    Value of the label
    label String
    Name of the label
    value String
    Value of the label
    label string
    Name of the label
    value string
    Value of the label
    label str
    Name of the label
    value str
    Value of the label
    label String
    Name of the label
    value String
    Value of the label

    Import

    #!/bin/bash
    
    # Docker secret cannot be imported as the secret data, once set, is never exposed again.
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    Docker pulumi/pulumi-docker
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the docker Terraform Provider.
     logo
    Viewing docs for Docker v4.11.2
    published on Wednesday, Apr 1, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.