You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that we've got a Docker container for our REST API, we can set up Docker Compose to run the container.
4
+
5
+
Docker Compose is most useful to start multiple Docker containers at the same time, specifying configuration values for them and dependencies between them.
6
+
7
+
Later on, I'll show you how to use Docker Compose to start both a PostgreSQL database and the REST API. For now, we'll use it only for the REST API, to simplify starting its container up.
8
+
9
+
If you have Docker Desktop installed, you already have Docker Compose. If you want to install Docker Compose in a system without Docker Desktop, please refer to the [official installation instructions](https://docs.docker.com/compose/install/).
10
+
11
+
## How to write a `docker-compose.yml` file
12
+
13
+
Create a file called `docker-compose.yml` in the root of your project (alongside your `Dockerfile`). Inside it, add the following contents:
14
+
15
+
```yaml
16
+
version: '3'
17
+
services:
18
+
web:
19
+
build: .
20
+
ports:
21
+
- "5000:5000"
22
+
volumes:
23
+
- .:/app
24
+
```
25
+
26
+
This small file is all you need to tell Docker Compose that you have a service, called `web`, which is built using the current directory (by default, that looks for a file called `Dockerfile`).
27
+
28
+
Other settings provided are:
29
+
30
+
- `ports`, used to map a port in your local computer to one in the container. Since our container runs the Flask app on port 5000, we're targeting that port so that any traffic we access in port 5000 of our computer is sent to the container's port 5000.
31
+
- `volumes`, to map a local directory into a directory within the container. This makes it so you don't have to rebuild the image each time you make a code change.
32
+
33
+
## How to run the Docker Compose services
34
+
35
+
Simply type:
36
+
37
+
```
38
+
docker compose up
39
+
```
40
+
41
+
And that will start all your services. For now, there's just one service, but later on when we add a database, this command will start everything.
42
+
43
+
When the services are running, you'll start seeing logs appear. These are the same logs as for running the `Dockerfile` on its own, but preceded by the service name.
44
+
45
+
In our case, we'll see `web-1 | ...` and the logs saying the service is running on `http://127.0.0.1:5000`. When you access that URL, you'll see the request logs printed in the console.
46
+
47
+
Congratulations, you've ran your first Docker Compose service!
48
+
49
+
## Rebuilding the Docker image
50
+
51
+
If you need to rebuild the Docker image of your REST API service for whatever reason (e.g. configuration changes), you can run:
52
+
53
+
```
54
+
docker compose up --build --force-recreate --no-deps web
55
+
```
56
+
57
+
More information [here](https://stackoverflow.com/a/50802581).
Copy file name to clipboardExpand all lines: docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md
+1-108
Original file line number
Diff line number
Diff line change
@@ -193,114 +193,7 @@ class UserModel(db.Model):
193
193
194
194
### Running our migration with string length changes
195
195
196
-
Now we want to create a new migration so that our changes to the `UserModel` will be applied. But because we're changing the length of a string column, we need to first make a modification to the Alembic configuration.
197
-
198
-
The changes we want to make are to add `compare_type=True`[^alembic_docs] in both `context.configure()` calls:
199
-
200
-
```python title="migrations/env.py"
201
-
from__future__import with_statement
202
-
203
-
import logging
204
-
from logging.config import fileConfig
205
-
206
-
from flask import current_app
207
-
208
-
from alembic import context
209
-
210
-
# this is the Alembic Config object, which provides
211
-
# access to the values within the .ini file in use.
0 commit comments