home / tils / til

Menu
  • GraphQL API

til: fly_fly-docker-registry.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
fly_fly-docker-registry.md fly Using the Fly Docker registry https://github.com/simonw/til/blob/main/fly/fly-docker-registry.md [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. 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. Today I figured out how to use Fly's own registry to deploy an app. ## Tagging images for the Fly registry 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. 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: flyctl apps create datasette-demo Fly app names must be globally unique across all of Fly - you will get an error if the app name is already taken. You can create an app with a random, freely available name using the `--generate-name` option: ``` ~ % flyctl apps create --generate-name ? Select Organization: Simon Willison (personal) New app created: rough-dew-1296 ``` Now that you have an app name, you can tag your Docker image using: registry.fly.io/your-app-name:unique-tag-for-your-image If you are building an image using Docker on your machine, you can run this command in the same directory as your `Dockerfile`: docker build -t registry.fly.io/datasette-demo:datasette-demo-v0 . ## Pushing images to the registry In order to push your image to Fly, you will first need to [authenticate](https://fly.io/docs/flyctl/auth-docker/). The `flyctl auth docker` command will do this for you: ``` ~ % flyctl auth docker Authentication successful. You can now tag and push images to registry.fly.io/{your-app} ``` 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: ```json { "auths": { "registry.fly.io": { "auth": "... secret token here ..." } , "experimental": "disabled", "stackOrchestrator": "swarm" } ``` Now you can push your image to the registry like this: docker push registry.fly.io/datasette-demo:datasette-demo-v0 ## Deploying an image Now that your image is pushed, you can deploy an instance of it like this: flyctl deploy --app datasette-demo \ --image registry.fly.io/datasette-demo:datasette-demo-v0 A few seconds later your app will be running at: https://name-of-your-app.fly.dev/ <p><a href="https://fly.io/" rel="nofollow">Fly.io</a> lets you deploy Docker containers that will be compiled as a Firecracker VM and run in locations around the world.</p> <p>Fly offer <a href="https://fly.io/docs/reference/builders/" rel="nofollow">a number of ways</a> to build and deploy apps. For many frameworks you can run <code>fly launch</code> and it will detect the framework and configure a container for you. For others you can pass it a <code>Dockerfile</code> which will be built and deployed. But you can also push your own images to a Docker registry and deploy them to Fly.</p> <p>Today I figured out how to use Fly's own registry to deploy an app.</p> <h2> <a id="user-content-tagging-images-for-the-fly-registry" class="anchor" href="#tagging-images-for-the-fly-registry" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Tagging images for the Fly registry</h2> <p>Fly's registry is called <code>registry.fly.io</code>. To use it, you need to tag your Docker images with a tag that begins with that string.</p> <p>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:</p> <pre><code>flyctl apps create datasette-demo </code></pre> <p>Fly app names must be globally unique across all of Fly - you will get an error if the app name is already taken.</p> <p>You can create an app with a random, freely available name using the <code>--generate-name</code> option:</p> <pre><code>~ % flyctl apps create --generate-name ? Select Organization: Simon Willison (personal) New app created: rough-dew-1296 </code></pre> <p>Now that you have an app name, you can tag your Docker image using:</p> <pre><code>registry.fly.io/your-app-name:unique-tag-for-your-image </code></pre> <p>If you are building an image using Docker on your machine, you can run this command in the same directory as your <code>Dockerfile</code>:</p> <pre><code>docker build -t registry.fly.io/datasette-demo:datasette-demo-v0 . </code></pre> <h2> <a id="user-content-pushing-images-to-the-registry" class="anchor" href="#pushing-images-to-the-registry" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Pushing images to the registry</h2> <p>In order to push your image to Fly, you will first need to <a href="https://fly.io/docs/flyctl/auth-docker/" rel="nofollow">authenticate</a>.</p> <p>The <code>flyctl auth docker</code> command will do this for you:</p> <pre><code>~ % flyctl auth docker Authentication successful. You can now tag and push images to registry.fly.io/{your-app} </code></pre> <p>This works by hooking into Docker's own authentication mechanism. You can see what it has done by looking at your <code>~/.docker/config.json</code> file. Mine looks like this:</p> <div class="highlight highlight-source-json"><pre>{ <span class="pl-ent">"auths"</span>: { <span class="pl-ent">"registry.fly.io"</span>: { <span class="pl-ent">"auth"</span>: <span class="pl-s"><span class="pl-pds">"</span>... secret token here ...<span class="pl-pds">"</span></span> } , <span class="pl-ent">"experimental"</span>: <span class="pl-s"><span class="pl-pds">"</span>disabled<span class="pl-pds">"</span></span>, <span class="pl-ent">"stackOrchestrator"</span>: <span class="pl-s"><span class="pl-pds">"</span>swarm<span class="pl-pds">"</span></span> }</pre></div> <p>Now you can push your image to the registry like this:</p> <pre><code>docker push registry.fly.io/datasette-demo:datasette-demo-v0 </code></pre> <h2> <a id="user-content-deploying-an-image" class="anchor" href="#deploying-an-image" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Deploying an image</h2> <p>Now that your image is pushed, you can deploy an instance of it like this:</p> <pre><code>flyctl deploy --app datasette-demo \ --image registry.fly.io/datasette-demo:datasette-demo-v0 </code></pre> <p>A few seconds later your app will be running at:</p> <pre><code>https://name-of-your-app.fly.dev/ </code></pre> <Binary: 75,011 bytes> 2022-05-21T19:33:19-07:00 2022-05-22T02:33:19+00:00 2022-05-21T19:33:19-07:00 2022-05-22T02:33:19+00:00 437f94106c0a14fe25514ad91ba6da7d fly-docker-registry
Powered by Datasette · How this site works · Code of conduct