This commit is contained in:
David Allen Arteaga
2021-08-08 14:42:35 -04:00
committed by GitHub
15 changed files with 191 additions and 29 deletions

View File

@@ -49,11 +49,11 @@ And now, we'll start migrating a service at a time into the compose file.
## Defining the App Service
To remember, this was the command we were using to define our app container (replace the ` \ ` characters with `` ` `` in Windows PowerShell).
To remember, this was the command we were using to define our app container.
```bash
docker run -dp 3000:3000 \
-w /app -v ${PWD}:/app \
-w /app -v "$(pwd):/app" \
--network todo-app \
-e MYSQL_HOST=mysql \
-e MYSQL_USER=root \
@@ -63,6 +63,20 @@ docker run -dp 3000:3000 \
sh -c "yarn install && yarn run dev"
```
If you are using PowerShell then use this command.
```powershell
docker run -dp 3000:3000 `
-w /app -v "$(pwd):/app" `
--network todo-app `
-e MYSQL_HOST=mysql `
-e MYSQL_USER=root `
-e MYSQL_PASSWORD=secret `
-e MYSQL_DB=todos `
node:12-alpine `
sh -c "yarn install && yarn run dev"
```
1. First, let's define the service entry and the image for the container. We can pick any name for the service.
The name will automatically become a network alias, which will be useful when defining our MySQL service.
@@ -102,7 +116,7 @@ docker run -dp 3000:3000 \
- 3000:3000
```
1. Next, we'll migrate both the working directory (`-w /app`) and the volume mapping (`-v ${PWD}:/app`) by using
1. Next, we'll migrate both the working directory (`-w /app`) and the volume mapping (`-v "$(pwd):/app"`) by using
the `working_dir` and `volumes` definitions. Volumes also has a [short](https://docs.docker.com/compose/compose-file/#short-syntax-3) and [long](https://docs.docker.com/compose/compose-file/#long-syntax-3) syntax.
One advantage of Docker Compose volume definitions is we can use relative paths from the current directory.
@@ -145,7 +159,7 @@ docker run -dp 3000:3000 \
### Defining the MySQL Service
Now, it's time to define the MySQL service. The command that we used for that container was the following (replace the ` \ ` characters with `` ` `` in Windows PowerShell):
Now, it's time to define the MySQL service. The command that we used for that container was the following:
```bash
docker run -d \
@@ -156,6 +170,17 @@ docker run -d \
mysql:5.7
```
If you are using PowerShell then use this command.
```powershell
docker run -d `
--network todo-app --network-alias mysql `
-v todo-mysql-data:/var/lib/mysql `
-e MYSQL_ROOT_PASSWORD=secret `
-e MYSQL_DATABASE=todos `
mysql:5.7
```
1. We will first define the new service and name it `mysql` so it automatically gets the network alias. We'll
go ahead and specify the image to use as well.