# ContainerImage

Constructs for types of container images.

Extends: ContainerImage
Superclass of: AssetImage, EcrImage, RepositoryImage, TagParameterContainerImage

- Source: [`aws-ecs/lib/container-image.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ecs/lib/container-image.ts#L12)
- Type last changed: v2.96.1 · 14 Sep 2023

## Example

```ts
declare const myFileSystem: efs.IFileSystem;
declare const myJobRole: iam.Role;
myFileSystem.grantRead(myJobRole);

const jobDefn = new batch.EcsJobDefinition(this, 'JobDefn', {
  container: new batch.EcsEc2ContainerDefinition(this, 'containerDefn', {
    image: ecs.ContainerImage.fromRegistry('public.ecr.aws/amazonlinux/amazonlinux:latest'),
    memory: cdk.Size.mebibytes(2048),
    cpu: 256,
    volumes: [batch.EcsVolume.efs({
      name: 'myVolume',
      fileSystem: myFileSystem,
      containerPath: '/Volumes/myVolume',
      useJobRole: true,
    })],
    jobRole: myJobRole,
  }),
});
```

## Initializer

```ts
new ContainerImage()
```

## Methods

- `bind(scope: Construct, containerDefinition: ContainerDefinition): ContainerImageConfig` — Called when the image is used by a ContainerDefinition.

- `fromAsset(directory: string, props?: AssetImageProps): AssetImage` (static) — Reference an image that's constructed directly from sources on disk.

  If you already have a `DockerImageAsset` instance, you can use the
  `ContainerImage.fromDockerImageAsset` method instead.

  **Parameters**

  - `directory` — The directory containing the Dockerfile.

- `fromDockerImageAsset(asset: DockerImageAsset): ContainerImage // chainable` (static) — Use an existing `DockerImageAsset` for this container image.

  **Parameters**

  - `asset` — The `DockerImageAsset` to use for this container definition.

- `fromEcrRepository(repository: IRepository, tag?: string): EcrImage` (static) — Reference an image in an ECR repository.

  **Parameters**

  - `tag` — If you don't specify this parameter, `latest` is used as default.

- `fromRegistry(name: string, props?: RepositoryImageProps): RepositoryImage` (static) — Reference an image on DockerHub or another online registry.

- `fromTarball(tarballFile: string): ContainerImage // chainable` (static) — Use an existing tarball for this container image.

  Use this method if the container image has already been created by another process (e.g. jib)
  and you want to add it as a container image asset.

  **Parameters**

  - `tarballFile` — Absolute path to the tarball.
