-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from tecladocode/jose/cou-537-cover-running-c…
…ommands-in-running-container-using-docker feat(compose): add new lecture on running commands in a container
- Loading branch information
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
docs/docs/04_docker_intro/05_run_commands_in_docker_containers/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# How to run commands inside a Docker container | ||
|
||
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. | ||
|
||
For example, later on in the course we will look at database migrations. | ||
|
||
To execute a database migration, we need to run a specific command, `flask db mgirate`. | ||
|
||
If we use Docker Compose, we'll need to run the command inside the running container, and not in a local terminal. | ||
|
||
You can run any arbitrary command in a running container like so: | ||
|
||
```bash | ||
docker compose exec web flask db migrate | ||
``` | ||
|
||
This command is split into 4 parts: | ||
|
||
- `docker compose`: uses the Docker Compose part of the Docker executable | ||
- `exec`: used to run a command in a specific Docker Compose service | ||
- `web`: which Docker Compose service to run the command in | ||
- `flask db migrate`: the command you want to run | ||
|
||
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters