Skip to content

Commit d49f20a

Browse files
committed
🐬Sync with codebase: docker compose
1 parent f0f234b commit d49f20a

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

content/en/docs/a1.hello-world-server.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ EXPOSE 8080
181181
> We can use `docker ps` command to see more info. To stop the container `docker stop <name>` and to remove the image `docker rmi -f <image-id>`.
182182
183183

184-
## `docker-compose.yml`
184+
## `compose.yml`
185185

186-
> [📖 Docker Compose](https://docs.docker.com/compose/) is a **tool for defining and running multi-container Docker applications**. With a single command, we can create and start all the services according to the content in the `docker-compose.yml` file. 🔍 If you are new to Docker Compose, I recommend you to read its [**Get Started guild**](https://docs.docker.com/compose/gettingstarted/) on its official documentation.
186+
> [📖 Docker Compose](https://docs.docker.com/compose/) is a **tool for defining and running multi-container Docker applications**. With a single command, we can create and start all the services according to the content in the `compose.yml` file. 🔍 If you are new to Docker Compose, I recommend you to read its [**Get Started guild**](https://docs.docker.com/compose/gettingstarted/) on its official documentation.
187187
188-
Let’s add the `docker-compose.yml`.
188+
Let’s add the `compose.yml`.
189189

190190
```dockerfile
191-
version: '3'
192191
services:
193192

194193
app:
@@ -197,9 +196,9 @@ services:
197196
- "8080:8080"
198197
```
199198

200-
- You can use `docker-compose build` and `docker-compose up` commands, to build and run the application.
199+
- You can use `docker compose build` and `docker compose up` commands, to build and run the application.
201200
- You should see the same response, `Hello, world!` text while visit [localhost:8080/hello](http://localhost:8080/hello) in the browser.
202-
- Use the `docker-compose down` command to stop the application.
201+
- Use the `docker compose down` command to stop the application.
203202

204203

205204
## An idiomatic structure

content/en/docs/a2.database-and-migrations.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ slug: "database-and-migrations"
44
---
55

66
> **👨‍🏫 Before we start...**
7-
> - We'll run a Postgres database via `docker-compose`.
7+
> - We'll run a Postgres database via `docker compose`.
88
> - There are a few popular database migration tools in the Go ecosystem, like [`golang-migrate/migrate`](https://github.com/golang-migrate/migrate), [`pressly/goose`](https://github.com/pressly/goose), [GORM migrations](http://gorm.io/docs/migration.html), etc. We selected [`pressly/goose`](https://github.com/pressly/goose) due to its simplicity, lesser resource usage, and customizability. But, instead of using its prebuilt binaries, we'll build a custom binary with static drivers, settings, and more simplified commands.
99
> - ⭐ We'll store all `SQL` database migration files in the `migrations` folder in the project root.
1010
@@ -30,10 +30,9 @@ In this article series, we are building a RESTful CRUD API for a simple bookshel
3030

3131
We'll use the [official Postgres Alpine Docker image](https://hub.docker.com/_/postgres) to build our development database.
3232

33-
Let's update the `docker-compose.yml` file,
33+
Let's update the `compose.yml` file,
3434

3535
```dockerfile
36-
version: '3'
3736
services:
3837

3938
app:
@@ -54,9 +53,9 @@ services:
5453
restart: always
5554
```
5655

57-
Run `docker-compose down` and `docker-compose up` to rerun the application with the database. Or, you can run `docker-compose up db` to run only the database.
56+
Run `docker compose down` and `docker compose up` to rerun the application with the database. Or, you can run `docker compose up db` to run only the database.
5857

59-
We can use `docker-compose ps` commands to see more info about the running containers.
58+
We can use `docker compose ps` commands to see more info about the running containers.
6059

6160
```
6261
NAME COMMAND SERVICE STATUS PORTS

content/en/docs/a3.configurations.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ slug: "configurations"
44
---
55

66
> **👨‍🏫 Before we start...**
7-
> - Configurations can be stored in a variety of formats, such as `.xml`, `.json`, `.env`, `.yaml`, and `.toml` files, as well as systems like [`etcd`](https://etcd.io/), [AWS Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), and [GCP Runtime Configurator](https://cloud.google.com/deployment-manager/runtime-configurator/). In this project, we will save the configurations in an `.env` file and use `docker-compose` to load them into the development environment.
7+
> - Configurations can be stored in a variety of formats, such as `.xml`, `.json`, `.env`, `.yaml`, and `.toml` files, as well as systems like [`etcd`](https://etcd.io/), [AWS Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), and [GCP Runtime Configurator](https://cloud.google.com/deployment-manager/runtime-configurator/). In this project, we will save the configurations in an `.env` file and use `docker compose` to load them into the development environment.
88
> - Go standard library provides the [`os.Getenv()`](https://golang.org/pkg/os/#Getenv) function to read each environment variable separately. But there are Go libraries such as [`spf13/viper`](https://github.com/spf13/viper), [`kelseyhightower/envconfig`](https://github.com/kelseyhightower/envconfig), [`caarlos0/env`](https://github.com/caarlos0/env), and [`joeshaw/envdecode`](https://github.com/joeshaw/envdecode) to read environment variables in bulk and populate them as a struct. We choose [`joeshaw/envdecode`](https://github.com/joeshaw/envdecode) for this project because it includes validations, zero-dependency, and ease of use.
99
1010

1111
## Populate environment variables with Docker
1212

13-
💡 We use `docker-compose` with the [`env_file`](https://docs.docker.com/compose/compose-file/compose-file-v3/#env_file) option to load the environment variables into the development environment. If you are using `docker run`, you can use the [`--env-file` option](https://docs.docker.com/engine/reference/commandline/run/#options) with it.
13+
💡 We use `docker compose` with the [`env_file`](https://docs.docker.com/compose/compose-file/compose-file-v3/#env_file) option to load the environment variables into the development environment. If you are using `docker run`, you can use the [`--env-file` option](https://docs.docker.com/engine/reference/commandline/run/#options) with it.
1414

1515
### 1. Add `.env`
1616

@@ -31,7 +31,7 @@ DB_DEBUG=true
3131

3232
> 💡 `SERVER_DEBUG` and `DB_DEBUG` will be utilized with the application logs and the GORM logs in the future steps.
3333
34-
### 2. update `docker-compose.yml`
34+
### 2. update `compose.yml`
3535

3636
```yml
3737
app:
@@ -43,7 +43,7 @@ DB_DEBUG=true
4343
- db
4444
```
4545
46-
Run `docker-compose down` and `docker-compose up` to populate the environment variables into the development environment.
46+
Run `docker compose down` and `docker compose up` to populate the environment variables into the development environment.
4747

4848

4949
## Adding configs to the API
@@ -201,7 +201,7 @@ func main() {
201201
}
202202
```
203203

204-
Run `docker-compose down`, `docker-compose build` and `docker-compose up` to run the application with the recent changes.
204+
Run `docker compose down`, `docker compose build` and `docker compose up` to run the application with the recent changes.
205205

206206
### 5. Run `go mod tidy`
207207

@@ -212,10 +212,9 @@ When we add a new package and use it, we have to run `go mod tidy` to reorganize
212212

213213
> 💡 Because we hardcoded `localhost` for the database host in the previous article, we encountered the `migrate up: dial tcp 127.0.0.1:3306: connect: connection refused` error with the `./bin/migrate up` command. But, with the current configurations, we should be able to run `./bin/migrate up` inside the docker image with the correct host. So, let's automate running migrations on application startup.
214214
215-
Usually, starting the database takes more time. So, we need to wait until the database is up before running database migrations. For this, we use `docker-compose` `db:`[`healthcheck`](https://docs.docker.com/compose/compose-file/#healthcheck) and `app:`[`depends_on:db:condition`](https://docs.docker.com/compose/compose-file/#depends_on) options.
215+
Usually, starting the database takes more time. So, we need to wait until the database is up before running database migrations. For this, we use `docker compose` `db:`[`healthcheck`](https://docs.docker.com/compose/compose-file/#healthcheck) and `app:`[`depends_on:db:condition`](https://docs.docker.com/compose/compose-file/#depends_on) options.
216216

217217
```yml
218-
version: '3.9'
219218
services:
220219

221220
app:

content/en/docs/a4.routes-and-openapi-specification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func main() {
149149
When we add a new package and use it, we have to run `go mod tidy` to reorganize the dependencies in the `go.mod` file.
150150

151151

152-
> 💡 You can use the `docker-compose down`, `docker-compose build`, and `docker-compose up` commands, to build and run the API application to test the recent changes. Alternatively, you can configure your IDE to run `cmd/api/main.go` locally, with the required env variables; Ex: [Running applications in the GoLand IDE](https://www.jetbrains.com/help/go/running-applications.html)
152+
> 💡 You can use the `docker compose down`, `docker compose build`, and `docker compose up` commands, to build and run the API application to test the recent changes. Alternatively, you can configure your IDE to run `cmd/api/main.go` locally, with the required env variables; Ex: [Running applications in the GoLand IDE](https://www.jetbrains.com/help/go/running-applications.html)
153153
154154

155155
## Generating OpenAPI specification

0 commit comments

Comments
 (0)