│ ├── .dockerignore
│ ├── .gitignore
│ ├── compose.yaml
│ ├── Dockerfile
│ ├── README.Docker.md
│ └── README.md
```
Now, run the following `docker compose up` command to start your application.
```console
$ docker compose up --build
```
Now test your API endpoint. Open a new terminal then make a request to the server using the curl commands:
Let's create an object with a post method
```console
$ curl -X 'POST' \
'http://localhost:8001/heroes/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"id": 1,
"name": "my hero",
"secret_name": "austing",
"age": 12
}'
```
You should receive the following response:
```json
{
"age": 12,
"id": 1,
"name": "my hero",
"secret_name": "austing"
}
```
Let's make a get request with the next curl command:
```console
curl -X 'GET' \
'http://localhost:8001/heroes/' \
-H 'accept: application/json'
```
You should receive the same response as above because it's the only one object we have in database.
```json
{
"age": 12,
"id": 1,
"name": "my hero",
"secret_name": "austing"
}
```
Press `ctrl+c` in the terminal to stop your application.
## Automatically update services
Use Compose Watch to automatically update your running Compose services as you
edit and save your code. For more details about Compose Watch, see [Use Compose
Watch](/manuals/compose/how-tos/file-watch.md).
Open your `compose.yaml` file in an IDE or text editor and then add the Compose
Watch instructions. The following is the updated `compose.yaml` file.
```yaml {hl_lines="17-20"}
services:
server:
build:
context: .
ports:
- 8001:8001
environment:
- POSTGRES_SERVER=db
- POSTGRES_USER=postgres
- POSTGRES_DB=example
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
depends_on:
db:
condition: service_healthy
secrets:
- db-password
develop:
watch:
- action: rebuild
path: .
db:
image: postgres
restart: always
user: postgres
secrets:
- db-password
volumes:
- db-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=example
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
expose:
- 5432
healthcheck:
test: ["CMD", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
volumes:
db-data:
secrets:
db-password:
file: db/password.txt
```
Run the following command to run your application with Compose Watch.
```console
$ docker compose watch
```
In a terminal, curl the application to get a response.
```console
$ curl http://localhost:8001
Hello, Docker!
```
Any changes to the application's source files on your local machine will now be immediately reflected in the running container.
Open `python-docker-dev-example/app.py` in an IDE or text editor and update the `Hello, Docker!` string by adding a few more exclamation marks.
```diff
- return 'Hello, Docker!'
+ return 'Hello, Docker!!!'
```
Save the changes to `app.py` and then wait a few seconds for the application to rebuild. Curl the application again and verify that the updated text appears.
```console
$ curl http://localhost:8001
Hello, Docker!!!
```
Press `ctrl+c` in the terminal to stop your application.
## Summary
In this section, you took a look at setting up your Compose file to add a local
database and persist data. You also learned how to use Compose Watch to automatically rebuild and run your container when you update your code.
Related information:
- [Compose file reference](/reference/compose-file/)
- [Compose file watch](/manuals/compose/how-tos/file-watch.md)
- [Multi-stage builds](/manuals/build/building/multi-stage.md)
## Next steps
In the next section, you'll learn how you can locally test and debug your workloads on Kubernetes before deploying.