-
Notifications
You must be signed in to change notification settings - Fork 1k
/
dockerfile.html.markerb
110 lines (82 loc) · 3.84 KB
/
dockerfile.html.markerb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: Deploy via Dockerfile
layout: language-and-framework-docs
sitemap: false
redirect_from: /docs/getting-started/dockerfile/
---
You already have a project wrapped up in a [docker container](https://docs.docker.com/engine/reference/builder/)? Great! Just deploy that!
The `fly launch` command detects your Dockerfile and builds it. If you have Docker running locally, it builds it on your machine. If not, it builds it on a Fly build machine. Once your container is built, it's deployed! Need some extra config? No sweat, we've got you covered. Let's take a look.
```cmd
fly launch
```
```output
...
Detected a Dockerfile app
? Choose an app name (leave blank to generate one):
? Select Organization: Mark Ericksen (personal)
...
? Choose a region for deployment: Los Angeles, California (US) (lax)
App will use 'lax' region as primary
Created app 'wispy-breeze-3322' in organization 'personal'
Admin URL: https://fly.io/apps/wispy-breeze-3322
Hostname: wispy-breeze-3322.fly.dev
? Would you like to set up a Postgresql database now? No
? Would you like to set up an Upstash Redis database now? No
Wrote config file fly.toml
? Would you like to deploy now?
```
Let `fly launch` generate an app name for you or pick your own.
Select the Fly.io [region](https://fly.io/docs/reference/regions/) to deploy to.
The launch command generates a `fly.toml` file for your project with the settings. You can deploy right away, or add some config first.
## _Config First!_
Most Dockerfiles expect some configuration settings through `ENV`. The generated `fly.toml` file has a place for you to add your custom `ENV` settings. It's the `[env]` block.
```toml
[env]
MY_SPECIAL_ENV = "some_value"
MAX_PLAYER_COUNT = "15"
```
Add the values your Dockerfile or container requires.
Sometimes you have secrets that shouldn't be checked in to `git` or shared publicly. For those settings, you can set them using [`fly secrets`](https://fly.io/docs/reference/secrets/#setting-secrets).
```cmd
flyctl secrets set MY_SECRET=romance
```
```output
Secrets are staged for the first deployment
```
You can list the secrets you've already set using `fly secrets list`
```cmd
fly secrets list
```
```
NAME DIGEST DATE
MY_SECRET b9e37b7b239ee4aefc75352fe3fa6dc6 1m20s ago
```
The values aren't displayed since they are secret!
## _Deploy Your App_
If you didn't previously deploy the app, you can do that now.
```cmd
fly deploy
```
```output
Validating /Users/someone/project/fly.toml
Platform: machines
✓ Configuration is valid
==> Building image
Remote builder fly-builder-restless-shadow-3063 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon 346B
...
Finished deploying
Visit your newly deployed app at https://wispy-breeze-3322.fly.dev/
```
By default, `fly deploy` builds the image using a remote builder. If you have Docker running locally and want to build locally, then run `fly deploy --local-only`. Once your container is built, it's deployed!
## _Open Your App_
Run `fly apps open` to open your deployed app in a browser.
You're off and running!
## _Taking it Further_
Lots of applications deployed in a container have some state that they want to keep. Here are a couple resources to check out for ways to do that.
- **[Persistent Volumes:](https://fly.io/docs/reference/volumes/)** You can create [persistent volumes](https://fly.io/docs/reference/volumes/) that you can mount into your container for reading and writing data that changes but isn't blown away when you deploy again.
- **[Postgres Database:](https://fly.io/docs/reference/postgres/#about-postgres-on-fly)** Deploy a [Fly Postgres Database](https://fly.io/docs/reference/postgres/#about-postgres-on-fly). It automatically creates a `DATABASE_URL` ENV when you attach it to your app.