DockerImage

class aws_cdk.DockerImage(image, _image_hash=None)

Bases: object

A Docker image.

ExampleMetadata:

infused

Example:

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/"}
    )
)
Parameters:
  • image (str) – The Docker image.

  • _image_hash (Optional[str]) –

Methods

cp(image_path, output_path=None)

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.

Parameters:
  • image_path (str) – the path in the Docker image.

  • output_path (Optional[str]) – the destination path for the copy operation.

Return type:

str

Returns:

the destination path

run(*, command=None, entrypoint=None, environment=None, network=None, platform=None, security_opt=None, user=None, volumes=None, volumes_from=None, working_directory=None)

Runs a Docker image.

Parameters:
  • command (Optional[Sequence[str]]) – The command to run in the container. Default: - run the command defined in the image

  • entrypoint (Optional[Sequence[str]]) – The entrypoint to run in the container. Default: - run the entrypoint defined in the image

  • environment (Optional[Mapping[str, str]]) – The environment variables to pass to the container. Default: - no environment variables.

  • network (Optional[str]) – Docker Networking options. Default: - no networking options

  • platform (Optional[str]) – Set platform if server is multi-platform capable. Requires Docker Engine API v1.38+. Example value: linux/amd64 Default: - no platform specified

  • security_opt (Optional[str]) – Security configuration when running the docker container. Default: - no security options

  • user (Optional[str]) – The user to use when running the container. Default: - root or image default

  • volumes (Optional[Sequence[Union[DockerVolume, Dict[str, Any]]]]) – Docker volumes to mount. Default: - no volumes are mounted

  • volumes_from (Optional[Sequence[str]]) – Where to mount the specified volumes from. Default: - no containers are specified to mount volumes from

  • working_directory (Optional[str]) – Working directory inside the container. Default: - image default

Return type:

None

to_json()

Provides a stable representation of this image for JSON serialization.

Return type:

str

Returns:

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

Attributes

image

The Docker image.

Static Methods

classmethod from_build(path, *, build_args=None, cache_disabled=None, cache_from=None, cache_to=None, file=None, platform=None, target_stage=None)

Builds a Docker image.

Parameters:
  • path (str) – The path to the directory containing the Docker file.

  • build_args (Optional[Mapping[str, str]]) – Build args. Default: - no build args

  • cache_disabled (Optional[bool]) – Disable the cache and pass --no-cache to the docker build command. Default: - cache is used

  • cache_from (Optional[Sequence[Union[DockerCacheOption, Dict[str, Any]]]]) – Cache from options to pass to the docker build command. Default: - no cache from args are passed

  • cache_to (Union[DockerCacheOption, Dict[str, Any], None]) – Cache to options to pass to the docker build command. Default: - no cache to args are passed

  • file (Optional[str]) – Name of the Dockerfile, must relative to the docker build path. Default: Dockerfile

  • platform (Optional[str]) – Set platform if server is multi-platform capable. Requires Docker Engine API v1.38+. Example value: linux/amd64 Default: - no platform specified

  • target_stage (Optional[str]) – Set build target for multi-stage container builds. Any stage defined afterwards will be ignored. Example value: build-env Default: - Build all stages defined in the Dockerfile

Return type:

DockerImage

classmethod from_registry(image)

Reference an image on DockerHub or another online registry.

Parameters:

image (str) – the image name.

Return type:

DockerImage