Now, run the following `docker compose up` command to start your application.
```console
$ docker compose up --build
```
In Ruby on Rails, `db:migrate` is a Rake task that is used to run migrations on the database. Migrations are a way to alter the structure of your database schema over time in a consistent and easy way.
```console
$ docker exec -it docker-ruby-on-rails-web-1 rake db:migrate RAILS_ENV=test
```
You will see a similar message like this:
`console
== 20240710193146 CreateWhales: migrating =====================================
-- create_table(:whales)
-> 0.0126s
== 20240710193146 CreateWhales: migrated (0.0127s) ============================
`
Refresh <http://localhost:3000> in your browser and add the whales.
Press `ctrl+c` in the terminal to stop your application and run `docker compose up` again, the whales are being persisted.
## 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="13-16"}
services:
web:
build: .
command: bundle exec rails s -b '0.0.0.0'
ports:
- "3000:3000"
depends_on:
- db
environment:
- RAILS_ENV=test
env_file: "webapp.env"
develop:
watch:
- action: rebuild
path: .
db:
image: postgres:latest
secrets:
- db-password
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
secrets:
db-password:
file: db/password.txt
```
Run the following command to run your application with Compose Watch.
```console
$ docker compose watch
```
Any changes to the application's source files on your local machine will now be immediately reflected in the running container.
Open `docker-ruby-on-rails/app/views/whales/index.html.erb` in an IDE or text editor and update the `Whales` string by adding an exclamation mark.
```diff
- <h1>Whales</h1>
+ <h1>Whales!</h1>
```
Save the changes to `index.html.erb` and then wait a few seconds for the application to rebuild. Go to the application again and verify that the updated text appears.
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.