1. Packages
  2. Docker Provider
  3. API Docs
  4. Volume
Docker v4.5.6 published on Tuesday, Sep 24, 2024 by Pulumi

docker.Volume

Explore with Pulumi AI

docker logo
Docker v4.5.6 published on Tuesday, Sep 24, 2024 by Pulumi

    Creates and destroys a volume in Docker. This can be used alongside docker.Container to prepare volumes that can be shared across containers.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as docker from "@pulumi/docker";
    
    const sharedVolume = new docker.Volume("shared_volume", {name: "shared_volume"});
    
    import pulumi
    import pulumi_docker as docker
    
    shared_volume = docker.Volume("shared_volume", name="shared_volume")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-docker/sdk/v4/go/docker"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := docker.NewVolume(ctx, "shared_volume", &docker.VolumeArgs{
    			Name: pulumi.String("shared_volume"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Docker = Pulumi.Docker;
    
    return await Deployment.RunAsync(() => 
    {
        var sharedVolume = new Docker.Volume("shared_volume", new()
        {
            Name = "shared_volume",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.docker.Volume;
    import com.pulumi.docker.VolumeArgs;
    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 sharedVolume = new Volume("sharedVolume", VolumeArgs.builder()
                .name("shared_volume")
                .build());
    
        }
    }
    
    resources:
      sharedVolume:
        type: docker:Volume
        name: shared_volume
        properties:
          name: shared_volume
    

    Create Volume Resource

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

    Constructor syntax

    new Volume(name: string, args?: VolumeArgs, opts?: CustomResourceOptions);
    @overload
    def Volume(resource_name: str,
               args: Optional[VolumeArgs] = None,
               opts: Optional[ResourceOptions] = None)
    
    @overload
    def Volume(resource_name: str,
               opts: Optional[ResourceOptions] = None,
               driver: Optional[str] = None,
               driver_opts: Optional[Mapping[str, str]] = None,
               labels: Optional[Sequence[VolumeLabelArgs]] = None,
               name: Optional[str] = None)
    func NewVolume(ctx *Context, name string, args *VolumeArgs, opts ...ResourceOption) (*Volume, error)
    public Volume(string name, VolumeArgs? args = null, CustomResourceOptions? opts = null)
    public Volume(String name, VolumeArgs args)
    public Volume(String name, VolumeArgs args, CustomResourceOptions options)
    
    type: docker:Volume
    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 VolumeArgs
    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 VolumeArgs
    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 VolumeArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args VolumeArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args VolumeArgs
    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 volumeResource = new Docker.Volume("volumeResource", new()
    {
        Driver = "string",
        DriverOpts = 
        {
            { "string", "string" },
        },
        Labels = new[]
        {
            new Docker.Inputs.VolumeLabelArgs
            {
                Label = "string",
                Value = "string",
            },
        },
        Name = "string",
    });
    
    example, err := docker.NewVolume(ctx, "volumeResource", &docker.VolumeArgs{
    	Driver: pulumi.String("string"),
    	DriverOpts: pulumi.StringMap{
    		"string": pulumi.String("string"),
    	},
    	Labels: docker.VolumeLabelArray{
    		&docker.VolumeLabelArgs{
    			Label: pulumi.String("string"),
    			Value: pulumi.String("string"),
    		},
    	},
    	Name: pulumi.String("string"),
    })
    
    var volumeResource = new Volume("volumeResource", VolumeArgs.builder()
        .driver("string")
        .driverOpts(Map.of("string", "string"))
        .labels(VolumeLabelArgs.builder()
            .label("string")
            .value("string")
            .build())
        .name("string")
        .build());
    
    volume_resource = docker.Volume("volumeResource",
        driver="string",
        driver_opts={
            "string": "string",
        },
        labels=[{
            "label": "string",
            "value": "string",
        }],
        name="string")
    
    const volumeResource = new docker.Volume("volumeResource", {
        driver: "string",
        driverOpts: {
            string: "string",
        },
        labels: [{
            label: "string",
            value: "string",
        }],
        name: "string",
    });
    
    type: docker:Volume
    properties:
        driver: string
        driverOpts:
            string: string
        labels:
            - label: string
              value: string
        name: string
    

    Volume 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 Volume resource accepts the following input properties:

    Driver string
    Driver type for the volume. Defaults to local.
    DriverOpts Dictionary<string, string>
    Options specific to the driver.
    Labels List<VolumeLabel>
    User-defined key/value metadata
    Name string
    The name of the Docker volume (will be generated if not provided).
    Driver string
    Driver type for the volume. Defaults to local.
    DriverOpts map[string]string
    Options specific to the driver.
    Labels []VolumeLabelArgs
    User-defined key/value metadata
    Name string
    The name of the Docker volume (will be generated if not provided).
    driver String
    Driver type for the volume. Defaults to local.
    driverOpts Map<String,String>
    Options specific to the driver.
    labels List<VolumeLabel>
    User-defined key/value metadata
    name String
    The name of the Docker volume (will be generated if not provided).
    driver string
    Driver type for the volume. Defaults to local.
    driverOpts {[key: string]: string}
    Options specific to the driver.
    labels VolumeLabel[]
    User-defined key/value metadata
    name string
    The name of the Docker volume (will be generated if not provided).
    driver str
    Driver type for the volume. Defaults to local.
    driver_opts Mapping[str, str]
    Options specific to the driver.
    labels Sequence[VolumeLabelArgs]
    User-defined key/value metadata
    name str
    The name of the Docker volume (will be generated if not provided).
    driver String
    Driver type for the volume. Defaults to local.
    driverOpts Map<String>
    Options specific to the driver.
    labels List<Property Map>
    User-defined key/value metadata
    name String
    The name of the Docker volume (will be generated if not provided).

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Mountpoint string
    The mountpoint of the volume.
    Id string
    The provider-assigned unique ID for this managed resource.
    Mountpoint string
    The mountpoint of the volume.
    id String
    The provider-assigned unique ID for this managed resource.
    mountpoint String
    The mountpoint of the volume.
    id string
    The provider-assigned unique ID for this managed resource.
    mountpoint string
    The mountpoint of the volume.
    id str
    The provider-assigned unique ID for this managed resource.
    mountpoint str
    The mountpoint of the volume.
    id String
    The provider-assigned unique ID for this managed resource.
    mountpoint String
    The mountpoint of the volume.

    Look up Existing Volume Resource

    Get an existing Volume 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?: VolumeState, opts?: CustomResourceOptions): Volume
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            driver: Optional[str] = None,
            driver_opts: Optional[Mapping[str, str]] = None,
            labels: Optional[Sequence[VolumeLabelArgs]] = None,
            mountpoint: Optional[str] = None,
            name: Optional[str] = None) -> Volume
    func GetVolume(ctx *Context, name string, id IDInput, state *VolumeState, opts ...ResourceOption) (*Volume, error)
    public static Volume Get(string name, Input<string> id, VolumeState? state, CustomResourceOptions? opts = null)
    public static Volume get(String name, Output<String> id, VolumeState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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:
    Driver string
    Driver type for the volume. Defaults to local.
    DriverOpts Dictionary<string, string>
    Options specific to the driver.
    Labels List<VolumeLabel>
    User-defined key/value metadata
    Mountpoint string
    The mountpoint of the volume.
    Name string
    The name of the Docker volume (will be generated if not provided).
    Driver string
    Driver type for the volume. Defaults to local.
    DriverOpts map[string]string
    Options specific to the driver.
    Labels []VolumeLabelArgs
    User-defined key/value metadata
    Mountpoint string
    The mountpoint of the volume.
    Name string
    The name of the Docker volume (will be generated if not provided).
    driver String
    Driver type for the volume. Defaults to local.
    driverOpts Map<String,String>
    Options specific to the driver.
    labels List<VolumeLabel>
    User-defined key/value metadata
    mountpoint String
    The mountpoint of the volume.
    name String
    The name of the Docker volume (will be generated if not provided).
    driver string
    Driver type for the volume. Defaults to local.
    driverOpts {[key: string]: string}
    Options specific to the driver.
    labels VolumeLabel[]
    User-defined key/value metadata
    mountpoint string
    The mountpoint of the volume.
    name string
    The name of the Docker volume (will be generated if not provided).
    driver str
    Driver type for the volume. Defaults to local.
    driver_opts Mapping[str, str]
    Options specific to the driver.
    labels Sequence[VolumeLabelArgs]
    User-defined key/value metadata
    mountpoint str
    The mountpoint of the volume.
    name str
    The name of the Docker volume (will be generated if not provided).
    driver String
    Driver type for the volume. Defaults to local.
    driverOpts Map<String>
    Options specific to the driver.
    labels List<Property Map>
    User-defined key/value metadata
    mountpoint String
    The mountpoint of the volume.
    name String
    The name of the Docker volume (will be generated if not provided).

    Supporting Types

    VolumeLabel, VolumeLabelArgs

    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

    Example

    Assuming you created a volume as follows

    #!/bin/bash

    docker volume create

    prints the long ID

    524b0457aa2a87dd2b75c74c3e4e53f406974249e63ab3ed9bf21e5644f9dc7d

    you provide the definition for the resource as follows

    terraform

    resource “docker_volume” “foo” {

    name = “524b0457aa2a87dd2b75c74c3e4e53f406974249e63ab3ed9bf21e5644f9dc7d”

    }

    then the import command is as follows

    #!/bin/bash

    $ pulumi import docker:index/volume:Volume foo 524b0457aa2a87dd2b75c74c3e4e53f406974249e63ab3ed9bf21e5644f9dc7d
    

    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.
    docker logo
    Docker v4.5.6 published on Tuesday, Sep 24, 2024 by Pulumi