Skip to content
v2.274.0

DockerImage Class ​

A Docker image.

Example ​

ts
const entry = '/path/to/function';
const image = DockerImage.fromBuild(entry);

new python.PythonFunction(this, 'function', {
  entry,
  runtime: Runtime.PYTHON_3_8,
  bundling: {
    buildArgs: { PIP_INDEX_URL: "https://your.index.url/simple/", PIP_EXTRA_INDEX_URL: "https://your.extra-index.url/simple/" },
  },
});
python
entry = "/path/to/function"
image = DockerImage.from_build(entry)

python.PythonFunction(self, "function",
    entry=entry,
    runtime=Runtime.PYTHON_3_8,
    bundling=python.BundlingOptions(
        build_args={"PIP_INDEX_URL": "https://your.index.url/simple/", "PIP_EXTRA_INDEX_URL": "https://your.extra-index.url/simple/"}
    )
)
java
String entry = "/path/to/function";
DockerImage image = DockerImage.fromBuild(entry);

PythonFunction.Builder.create(this, "function")
        .entry(entry)
        .runtime(Runtime.PYTHON_3_8)
        .bundling(BundlingOptions.builder()
                .buildArgs(Map.of("PIP_INDEX_URL", "https://your.index.url/simple/", "PIP_EXTRA_INDEX_URL", "https://your.extra-index.url/simple/"))
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var entry = "/path/to/function";
var image = DockerImage.FromBuild(entry);

new PythonFunction(this, "function", new PythonFunctionProps {
    Entry = entry,
    Runtime = Runtime.PYTHON_3_8,
    Bundling = new BundlingOptions {
        BuildArgs = new Dictionary<string, string> { { "PIP_INDEX_URL", "https://your.index.url/simple/" }, { "PIP_EXTRA_INDEX_URL", "https://your.extra-index.url/simple/" } }
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
entry := "/path/to/function"
image := awscdk.DockerImage_FromBuild(entry)

python.NewPythonFunction(this, jsii.String("function"), &PythonFunctionProps{
	Entry: jsii.String(Entry),
	Runtime: awscdk.Runtime_PYTHON_3_8(),
	Bundling: &BundlingOptions{
		BuildArgs: map[string]*string{
			"PIP_INDEX_URL": jsii.String("https://your.index.url/simple/"),
			"PIP_EXTRA_INDEX_URL": jsii.String("https://your.extra-index.url/simple/"),
		},
	},
})

Initializer ​

ts
new DockerImage(image: string, _imageHash?: string)
python
DockerImage(image: str, _image_hash: typing.Optional[str] = None)
java
new DockerImage(String image, String _imageHash)
csharp
new DockerImage(string image, string? _imageHash = null)
go
NewDockerImage(Image *string, _imageHash *string)

Properties ​

imagestringimagestrimageStringImagestringImage*stringrequired#
The Docker image.

Methods ​

cp(imagePath: string, outputPath?: string): stringdef cp(self, image_path: str, output_path: typing.Optional[str] = None) -> strpublic String cp(String imagePath, String outputPath)public string Cp(string imagePath, string? outputPath = null)func Cp(ImagePath *string, OutputPath *string) *string#
Copies a file or directory out of the Docker image to the local filesystem.

If outputPath is omitted the destination path is a temporary directory.

2 parameters · returns

Parameters

  • imagePathimage_pathimagePathimagePathImagePath — the path in the Docker image.
  • outputPathoutput_pathoutputPathoutputPathOutputPath — the destination path for the copy operation.

Returns: the destination path

fromBuild(path: string, options?: DockerBuildOptions): DockerImage // chainable@staticmethod def from_build(path: str, options: typing.Optional[DockerBuildOptions] = None) -> DockerImagepublic static DockerImage fromBuild(String path, DockerBuildOptions options)public static DockerImage FromBuild(string path, DockerBuildOptions? options = null)func FromBuild(Path *string, Options DockerBuildOptions) DockerImagestatic#
Builds a Docker image.
2 parameters

Parameters

  • pathpathpathpathPath — The path to the directory containing the Docker file.
  • optionsoptionsoptionsoptionsOptions — Docker build options.
fromRegistry(image: string): DockerImage // chainable@staticmethod def from_registry(image: str) -> DockerImagepublic static DockerImage fromRegistry(String image)public static DockerImage FromRegistry(string image)func FromRegistry(Image *string) DockerImagestatic#
Reference an image on DockerHub or another online registry.
1 parameter

Parameters

  • imageimageimageimageImage — the image name.
run(options?: DockerRunOptions): voiddef run(self, options: typing.Optional[DockerRunOptions] = None) -> Nonepublic void run(DockerRunOptions options)public void Run(DockerRunOptions? options = null)func Run(Options DockerRunOptions)#
Runs a Docker image.
toJSON(): stringdef to_json(self, ) -> strpublic String toJSON()public string ToJSON()func ToJSON() *string#
Provides a stable representation of this image for JSON serialization.
returns

Returns: The overridden image name if set or image hash name in that order