-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add til how to use default values in docker compose yml
fixes: #153
- Loading branch information
1 parent
29a0364
commit 6630822
Showing
5 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ tasks: | |
|
||
new_post: | ||
cmds: | ||
- scripts/add "{{.CLI_ARGS}}" | ||
- new_post "{{.CLI_ARGS}}" | ||
|
||
new_talk: | ||
cmds: | ||
|
Binary file added
BIN
+350 KB
...2023-12-30-til-how-to-use-default-values-in-docker-compose-yml/images/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions
42
...t/posts/2023-12-30-til-how-to-use-default-values-in-docker-compose-yml/index.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,42 @@ | ||
--- | ||
title: "TIL: How to Use Default Values in docker-compose.yml" | ||
date: 2023-12-30 | ||
canonicalURL: https://haseebmajid.dev/posts/2023-12-30-til-how-to-use-default-values-in-docker-compose-yml | ||
tags: | ||
- docker-compose | ||
- bash | ||
series: | ||
- TIL | ||
--- | ||
|
||
**TIL: How to Use Default Values in docker-compose.yml** | ||
|
||
Sometimes we want to use env variables in our docker-compose files like so: | ||
|
||
```yml | ||
services: | ||
client: | ||
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/nginx | ||
ports: | ||
- 8000:80 | ||
``` | ||
Here we are going to use the GitLab CI dependency proxy to pull our Nginx image, so we can speed up our pipelines but | ||
also avoid being rate limited by docker hub. However, when running this locally, we will need to make sure the | ||
`CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX` env variable is set. Which just adds a bit more work, instead we can leverage | ||
some of the special syntax docker-compose provides [^1], which I think it inherits from bash. | ||
|
||
Where we can use interpolation to set default values if the env variable is not set: | ||
|
||
```yml | ||
services: | ||
client: | ||
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX:-docker.io}/nginx | ||
ports: | ||
- 8000:80 | ||
``` | ||
|
||
In this case, `:-` will use docker.io if the env variable is not set or is empty. There are several other variations | ||
you can find in the footnote below. | ||
|
||
[^1]: https://docs.docker.com/compose/environment-variables/env-file/ |
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
This file was deleted.
Oops, something went wrong.