|
| 1 | +# Using the Fly Docker registry |
| 2 | + |
| 3 | +[Fly.io](https://fly.io/) lets you deploy Docker containers that will be compiled as a Firecracker VM and run in locations around the world. |
| 4 | + |
| 5 | +Fly offer [a number of ways](https://fly.io/docs/reference/builders/) to build and deploy apps. For many frameworks you can run `fly launch` and it will detect the framework and configure a container for you. For others you can pass it a `Dockerfile` which will be built and deployed. But you can also push your own images to a Docker registry and deploy them to Fly. |
| 6 | + |
| 7 | +Today I figured out how to use Fly's own registry to deploy an app. |
| 8 | + |
| 9 | +## Tagging images for the Fly registry |
| 10 | + |
| 11 | +Fly's registry is called `registry.fly.io`. To use it, you need to tag your Docker images with a tag that begins with that string. |
| 12 | + |
| 13 | +Every Fly app gets its own registry subdomain. You can create apps in a number of ways, but the easiest is to use the Fly CLI: |
| 14 | + |
| 15 | + flyctl apps create datasette-demo |
| 16 | + |
| 17 | +Fly app names must be globally unique across all of Fly - you will get an error if the app name is already taken. |
| 18 | + |
| 19 | +You can create an app with a random, freely available name using the `--generate-name` option: |
| 20 | + |
| 21 | +``` |
| 22 | +~ % flyctl apps create --generate-name |
| 23 | +? Select Organization: Simon Willison (personal) |
| 24 | +New app created: rough-dew-1296 |
| 25 | +``` |
| 26 | + |
| 27 | +Now that you have an app name, you can tag your Docker image using: |
| 28 | + |
| 29 | + registry.fly.io/your-app-name:unique-tag-for-your-image |
| 30 | + |
| 31 | +If you are building an image using Docker on your machine, you can run this command in the same directory as your `Dockerfile`: |
| 32 | + |
| 33 | + docker build -t registry.fly.io/datasette-demo:datasette-demo-v0 . |
| 34 | + |
| 35 | +## Pushing images to the registry |
| 36 | + |
| 37 | +In order to push your image to Fly, you will first need to [authenticate](https://fly.io/docs/flyctl/auth-docker/). |
| 38 | + |
| 39 | +The `flyctl auth docker` command will do this for you: |
| 40 | +``` |
| 41 | +~ % flyctl auth docker |
| 42 | +Authentication successful. You can now tag and push images to registry.fly.io/{your-app} |
| 43 | +``` |
| 44 | +This works by hooking into Docker's own authentication mechanism. You can see what it has done by looking at your `~/.docker/config.json` file. Mine looks like this: |
| 45 | + |
| 46 | +```json |
| 47 | +{ |
| 48 | + "auths": { |
| 49 | + "registry.fly.io": { |
| 50 | + "auth": "... secret token here ..." |
| 51 | + } |
| 52 | + , |
| 53 | + "experimental": "disabled", |
| 54 | + "stackOrchestrator": "swarm" |
| 55 | +} |
| 56 | +``` |
| 57 | +Now you can push your image to the registry like this: |
| 58 | + |
| 59 | + docker push registry.fly.io/datasette-demo:datasette-demo-v0 |
| 60 | + |
| 61 | +## Deploying an image |
| 62 | + |
| 63 | +Now that your image is pushed, you can deploy an instance of it like this: |
| 64 | + |
| 65 | + flyctl deploy --app datasette-demo \ |
| 66 | + --image registry.fly.io/datasette-demo:datasette-demo-v0 |
| 67 | + |
| 68 | +A few seconds later your app will be running at: |
| 69 | + |
| 70 | + https://name-of-your-app.fly.dev/ |
0 commit comments