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,
cluster: Optional[VolumeClusterArgs] = 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()
{
Cluster = new Docker.Inputs.VolumeClusterArgs
{
Availability = "string",
Group = "string",
Id = "string",
LimitBytes = "string",
RequiredBytes = "string",
Scope = "string",
Sharing = "string",
TopologyPreferred = "string",
TopologyRequired = "string",
Type = "string",
},
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{
Cluster: &docker.VolumeClusterArgs{
Availability: pulumi.String("string"),
Group: pulumi.String("string"),
Id: pulumi.String("string"),
LimitBytes: pulumi.String("string"),
RequiredBytes: pulumi.String("string"),
Scope: pulumi.String("string"),
Sharing: pulumi.String("string"),
TopologyPreferred: pulumi.String("string"),
TopologyRequired: pulumi.String("string"),
Type: pulumi.String("string"),
},
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()
.cluster(VolumeClusterArgs.builder()
.availability("string")
.group("string")
.id("string")
.limitBytes("string")
.requiredBytes("string")
.scope("string")
.sharing("string")
.topologyPreferred("string")
.topologyRequired("string")
.type("string")
.build())
.driver("string")
.driverOpts(Map.of("string", "string"))
.labels(VolumeLabelArgs.builder()
.label("string")
.value("string")
.build())
.name("string")
.build());
volume_resource = docker.Volume("volumeResource",
cluster={
"availability": "string",
"group": "string",
"id": "string",
"limit_bytes": "string",
"required_bytes": "string",
"scope": "string",
"sharing": "string",
"topology_preferred": "string",
"topology_required": "string",
"type": "string",
},
driver="string",
driver_opts={
"string": "string",
},
labels=[{
"label": "string",
"value": "string",
}],
name="string")
const volumeResource = new docker.Volume("volumeResource", {
cluster: {
availability: "string",
group: "string",
id: "string",
limitBytes: "string",
requiredBytes: "string",
scope: "string",
sharing: "string",
topologyPreferred: "string",
topologyRequired: "string",
type: "string",
},
driver: "string",
driverOpts: {
string: "string",
},
labels: [{
label: "string",
value: "string",
}],
name: "string",
});
type: docker:Volume
properties:
cluster:
availability: string
group: string
id: string
limitBytes: string
requiredBytes: string
scope: string
sharing: string
topologyPreferred: string
topologyRequired: string
type: string
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:
- Cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- Driver string
- Driver type for the volume. Defaults to
local. - Driver
Opts Dictionary<string, string> - Options specific to the driver.
- Labels
List<Volume
Label> - User-defined key/value metadata
- Name string
- The name of the Docker volume (will be generated if not provided).
- Cluster
Volume
Cluster Args - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- Driver string
- Driver type for the volume. Defaults to
local. - Driver
Opts map[string]string - Options specific to the driver.
- Labels
[]Volume
Label Args - User-defined key/value metadata
- Name string
- The name of the Docker volume (will be generated if not provided).
- cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver String
- Driver type for the volume. Defaults to
local. - driver
Opts Map<String,String> - Options specific to the driver.
- labels
List<Volume
Label> - User-defined key/value metadata
- name String
- The name of the Docker volume (will be generated if not provided).
- cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver string
- Driver type for the volume. Defaults to
local. - driver
Opts {[key: string]: string} - Options specific to the driver.
- labels
Volume
Label[] - User-defined key/value metadata
- name string
- The name of the Docker volume (will be generated if not provided).
- cluster
Volume
Cluster Args - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver str
- Driver type for the volume. Defaults to
local. - driver_
opts Mapping[str, str] - Options specific to the driver.
- labels
Sequence[Volume
Label Args] - User-defined key/value metadata
- name str
- The name of the Docker volume (will be generated if not provided).
- cluster Property Map
- Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver String
- Driver type for the volume. Defaults to
local. - driver
Opts 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,
cluster: Optional[VolumeClusterArgs] = 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) -> Volumefunc 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)resources: _: type: docker:Volume 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.
- Cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- Driver string
- Driver type for the volume. Defaults to
local. - Driver
Opts Dictionary<string, string> - Options specific to the driver.
- Labels
List<Volume
Label> - 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).
- Cluster
Volume
Cluster Args - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- Driver string
- Driver type for the volume. Defaults to
local. - Driver
Opts map[string]string - Options specific to the driver.
- Labels
[]Volume
Label Args - 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).
- cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver String
- Driver type for the volume. Defaults to
local. - driver
Opts Map<String,String> - Options specific to the driver.
- labels
List<Volume
Label> - 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).
- cluster
Volume
Cluster - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver string
- Driver type for the volume. Defaults to
local. - driver
Opts {[key: string]: string} - Options specific to the driver.
- labels
Volume
Label[] - 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).
- cluster
Volume
Cluster Args - Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver str
- Driver type for the volume. Defaults to
local. - driver_
opts Mapping[str, str] - Options specific to the driver.
- labels
Sequence[Volume
Label Args] - 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).
- cluster Property Map
- Cluster-specific options for volume creation. Only works if the Docker daemon is running in swarm mode and is the swarm manager.
- driver String
- Driver type for the volume. Defaults to
local. - driver
Opts 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
VolumeCluster, VolumeClusterArgs
- Availability string
- Availability of the volume. Can be
active(default),pause, ordrain. - Group string
- Cluster Volume group
- Id string
- The ID of the cluster volume.
- Limit
Bytes string - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- Required
Bytes string - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- Scope string
- The scope of the volume. Can be
single(default) ormulti. - string
- The sharing mode. Can be
none(default),readonly,onewriterorall. - Topology
Preferred string - A topology that the Cluster Volume would be preferred in
- Topology
Required string - A topology that the Cluster Volume must be accessible from
- Type string
- Cluster Volume access type. Can be
mountorblock(default).
- Availability string
- Availability of the volume. Can be
active(default),pause, ordrain. - Group string
- Cluster Volume group
- Id string
- The ID of the cluster volume.
- Limit
Bytes string - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- Required
Bytes string - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- Scope string
- The scope of the volume. Can be
single(default) ormulti. - string
- The sharing mode. Can be
none(default),readonly,onewriterorall. - Topology
Preferred string - A topology that the Cluster Volume would be preferred in
- Topology
Required string - A topology that the Cluster Volume must be accessible from
- Type string
- Cluster Volume access type. Can be
mountorblock(default).
- availability String
- Availability of the volume. Can be
active(default),pause, ordrain. - group String
- Cluster Volume group
- id String
- The ID of the cluster volume.
- limit
Bytes String - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- required
Bytes String - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- scope String
- The scope of the volume. Can be
single(default) ormulti. - String
- The sharing mode. Can be
none(default),readonly,onewriterorall. - topology
Preferred String - A topology that the Cluster Volume would be preferred in
- topology
Required String - A topology that the Cluster Volume must be accessible from
- type String
- Cluster Volume access type. Can be
mountorblock(default).
- availability string
- Availability of the volume. Can be
active(default),pause, ordrain. - group string
- Cluster Volume group
- id string
- The ID of the cluster volume.
- limit
Bytes string - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- required
Bytes string - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- scope string
- The scope of the volume. Can be
single(default) ormulti. - string
- The sharing mode. Can be
none(default),readonly,onewriterorall. - topology
Preferred string - A topology that the Cluster Volume would be preferred in
- topology
Required string - A topology that the Cluster Volume must be accessible from
- type string
- Cluster Volume access type. Can be
mountorblock(default).
- availability str
- Availability of the volume. Can be
active(default),pause, ordrain. - group str
- Cluster Volume group
- id str
- The ID of the cluster volume.
- limit_
bytes str - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- required_
bytes str - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- scope str
- The scope of the volume. Can be
single(default) ormulti. - str
- The sharing mode. Can be
none(default),readonly,onewriterorall. - topology_
preferred str - A topology that the Cluster Volume would be preferred in
- topology_
required str - A topology that the Cluster Volume must be accessible from
- type str
- Cluster Volume access type. Can be
mountorblock(default).
- availability String
- Availability of the volume. Can be
active(default),pause, ordrain. - group String
- Cluster Volume group
- id String
- The ID of the cluster volume.
- limit
Bytes String - Minimum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- required
Bytes String - Maximum size of the Cluster Volume in human readable memory bytes (like 128MiB, 2GiB, etc). Must be in format of KiB, MiB, Gib, Tib or PiB.
- scope String
- The scope of the volume. Can be
single(default) ormulti. - String
- The sharing mode. Can be
none(default),readonly,onewriterorall. - topology
Preferred String - A topology that the Cluster Volume would be preferred in
- topology
Required String - A topology that the Cluster Volume must be accessible from
- type String
- Cluster Volume access type. Can be
mountorblock(default).
VolumeLabel, VolumeLabelArgs
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
dockerTerraform Provider.
