# Deploy an image

Source: https://openpanel.sh/docs/deploy/images

Run a public container image from Docker Hub or another registry, and move it to a new tag.

A service can run a container image that is already built: from Docker Hub, GitHub's registry or any other registry that serves it publicly. Your servers pull the image when the deployment rolls out.

## The image and its tag [#the-image-and-its-tag]

| Setting | What it takes |
|---|---|
| **Image** | A name such as `nginx`, `bitnami/redis` or `ghcr.io/org/app`. Without a registry in front, the image comes from Docker Hub. Lowercase letters, digits, `.`, `_`, `-` and `/`, with an optional registry and port. |
| **Tag** | Up to 128 letters, digits, dots, dashes or underscores, such as `1.27` or `v2.3.0`. `latest` when you give none. |

<Callout type="warn" title="Public images only, by tag">
Your servers pull images without signing in to a registry, so the image must be public. An image cannot be pinned to a digest (`@sha256:…`) yet; use a tag that you never move, such as a version or a commit hash.
</Callout>

## Create a service from an image [#create-a-service-from-an-image]

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
Open the project. Click **New service** and choose **A Docker image**. Type the image as you would pull it, such as `nginx:1.27`: the tag after the colon goes to **Tag**. Set its port under **Networking**, tick a server under **Servers it may run on**, and click **Create service**.
</Tab>

<Tab value="CLI">
```sh
openpanel services create web --project shop \
  --image nginx:1.27 --public --port http:80 --server my-server
```

`--image` takes the image and its tag in one, split at the last `:`. `--server` names a server the service may run on; repeat it for several.
</Tab>

<Tab value="API">
```sh
curl -X POST "https://openpanel.sh/api/v1/projects/$PROJECT_ID/services" \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "web",
    "source": { "kind": "image", "image": "nginx", "tag": "1.27" },
    "exposure": "public",
    "ports": [{ "protocol": "http", "port": 80 }],
    "serverIds": ["'"$SERVER_ID"'"]
  }'
```
</Tab>
</Tabs>

Every other setting, from replicas to the health check, is on [Service settings](/docs/projects/settings). Then [deploy](/docs/deploy#deploy-a-service) it.

The container runs the image's own command. To run another, set a start command: `--start "<command>"` in the CLI or `startCommand` in the API. OpenPanel runs it with `/bin/sh -c`.

## Move to a new tag [#move-to-a-new-tag]

Change the tag, then deploy. The change does nothing until the deploy.

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
Open the project and click the service on the canvas. On its **Settings** tab, change the **Tag** in the **Source** card and click **Save**. Then click **Deploy** on its **Overview** tab.
</Tab>

<Tab value="CLI">
```sh
openpanel services update web --project shop --image nginx:1.28
openpanel deploy web --project shop --wait
```
</Tab>

<Tab value="API">
```sh
curl -X PATCH "https://openpanel.sh/api/v1/services/$SERVICE_ID" \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "source": { "kind": "image", "image": "nginx", "tag": "1.28" } }'

curl -X POST "https://openpanel.sh/api/v1/services/$SERVICE_ID/deployments" \
  -H "Authorization: Bearer $OPENPANEL_TOKEN"
```
</Tab>
</Tabs>

To build the image in your own CI and deploy it from there, see [Deploy from CI](/docs/deploy/ci).

## What your server does [#what-your-server-does]

When the deployment rolls out, the agent on each server it is placed on pulls the image, gives it a name of its own for this deployment, and starts the containers beside the ones that run now. A [rollback](/docs/deploy/rollbacks) pulls the earlier tag again.

If the pull fails, the deployment fails with "The image could not be pulled:" and the registry's reason, and what ran before keeps running. See [A deploy or a health check fails](/docs/troubleshooting/deploy-fails).