Skip to content

Commit 49a3a7b

Browse files
committed
feat(compose): add new lecture on running commands in a container
1 parent ed92dab commit 49a3a7b

File tree

2 files changed

+25
-1
lines changed
  • docs/docs
    • 04_docker_intro/05_run_commands_in_docker_containers
    • 11_deploy_to_render/06_run_everything_docker_compose

2 files changed

+25
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# How to run commands inside a Docker container
2+
3+
If you run your API using Docker Compose, with the `docker compose up` command, you may also want to be able to execute arbitrary shell commands in the container.
4+
5+
For example, later on in the course we will look at database migrations.
6+
7+
To execute a database migration, we need to run a specific command, `flask db mgirate`.
8+
9+
If we use Docker Compose, we'll need to run the command inside the running container, and not in a local terminal.
10+
11+
You can run any arbitrary command in a running container like so:
12+
13+
```bash
14+
docker compose exec web flask db migrate
15+
```
16+
17+
This command is split into 4 parts:
18+
19+
- `docker compose`: uses the Docker Compose part of the Docker executable
20+
- `exec`: used to run a command in a specific Docker Compose service
21+
- `web`: which Docker Compose service to run the command in
22+
- `flask db migrate`: the command you want to run
23+
24+
That's all! Just remember while following the course, that if I run any commands in my local terminal and you are using Docker Compose, you should precede the commands with `docker compose exec web`.

docs/docs/11_deploy_to_render/06_run_everything_docker_compose/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ volumes:
3131
The `postgres` image accepts various environment variables, among them:
3232

3333
- `POSTGRES_PASSWORD`, defaulting to `postgres`
34-
- `POSTGERS_DB`, defaulting to `postgres`
34+
- `POSTGRES_DB`, defaulting to `postgres`
3535
- `POSTGRES_USER`, defaulting to `postgres`
3636
- `POSTGRES_HOST`, defaulting to `localhost`
3737
- `POSTGRES_PORT`, defaulting to `5432`

0 commit comments

Comments
 (0)