# Launch from a machine image

Launch a new instance as a copy of the disk one of your machine images was taken from.

The new instance boots from a copy of the disk the image was taken from: everything that was on
that disk is on the new one. Replace the ids with your own.

## Prerequisites

- Permission for `ec2:RunInstances`. In the console, listing your images also needs
  `ec2:DescribeImages`.
- An `available` image of yours in the region you launch in.
- An instance type of the image's architecture with a disk at least as big as the one the image was
  taken from.

## Launch

**Console**
1. Open **Compute**, then **Images**, and choose an image whose state is available to open its
   details.
2. Choose **Launch instance from this image**. The **Create instance** form opens with the image
   chosen.
3. Fill in the rest (see [Launch an instance](launch-an-instance.md)) and choose **Create
   instance**.

Your available images are also listed first, under **My images**, in the form's **Boot image**
picker, when they are in the chosen region and match the instance type's architecture.

**CLI**
```sh
dcloud ec2 instances run --region-id de1 --server-type performance-2 \
  --machine-image-id ewi-1a2b3c4d --name web-02
```

**API**
```http
POST /ec2/api/instances
{ "serverType": "performance-2", "machineImageId": "ewi-1a2b3c4d", "regionId": "de1", "name": "web-02" }
```

**Terraform**
Set `machine_image_id` instead of `image_id` on the `dcloud_instance`.

Give `machineImageId` instead of `imageId`, never both.

## When the launch is refused

- `404` "Machine image not found".
- `409` "Machine image … is …; only an available image can launch an instance".
- `409` "The snapshot behind … no longer exists at the provider; deregister the image", or "The
  snapshot behind … is … at the provider" while it is not available there.
- `400` "Machine image … is in region …; launch it there".
- `400` "Machine image … is x86_64; … runs arm64" (the architectures differ).
- `400` "… has a … GiB disk; … was taken from a … GiB disk and needs at least that much".

## Result

The answer is `201` with the instance in state `pending`, as for any launch. The instance records
the image it came from, and an image taken from that instance inherits its OS details. The image
works in every zone of its region: to run a copy in another zone, give that zone at launch.

## Related

- [Create a machine image](create-a-machine-image.md)
- `ec2.instances.run` · `dcloud ec2 instances run` · `dcloud_instance`
