Skip to content

Commit fe2686f

Browse files
Merge pull request docker#70 from StefanScherer/powershell
Show multiline PowerShell commands
2 parents 3641a64 + a33ed89 commit fe2686f

3 files changed

Lines changed: 69 additions & 10 deletions

File tree

docs/tutorial/multi-container-apps/index.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ For now, we will create the network first and attach the MySQL container at star
3838
```
3939

4040
1. Start a MySQL container and attach it the network. We're also going to define a few environment variables that the
41-
database will use to initialize the database (see the "Environment Variables" section in the [MySQL Docker Hub listing](https://hub.docker.com/_/mysql/)) (replace the ` \ ` characters with `` ` `` in Windows PowerShell).
41+
database will use to initialize the database (see the "Environment Variables" section in the [MySQL Docker Hub listing](https://hub.docker.com/_/mysql/)).
4242
4343
```bash
4444
docker run -d \
@@ -49,6 +49,17 @@ For now, we will create the network first and attach the MySQL container at star
4949
mysql:5.7
5050
```
5151
52+
If you are using PowerShell then use this command.
53+
54+
```powershell
55+
docker run -d `
56+
--network todo-app --network-alias mysql `
57+
-v todo-mysql-data:/var/lib/mysql `
58+
-e MYSQL_ROOT_PASSWORD=secret `
59+
-e MYSQL_DATABASE=todos `
60+
mysql:5.7
61+
```
62+
5263
You'll also see we specified the `--network-alias` flag. We'll come back to that in just a moment.
5364
5465
!!! info "Pro-tip"
@@ -165,11 +176,11 @@ The todo app supports the setting of a few environment variables to specify MySQ
165176

166177
With all of that explained, let's start our dev-ready container!
167178
168-
1. We'll specify each of the environment variables above, as well as connect the container to our app network (replace the ` \ ` characters with `` ` `` in Windows PowerShell).
179+
1. We'll specify each of the environment variables above, as well as connect the container to our app network.
169180

170181
```bash hl_lines="3 4 5 6 7"
171182
docker run -dp 3000:3000 \
172-
-w /app -v ${PWD}:/app \
183+
-w /app -v "$(pwd):/app" \
173184
--network todo-app \
174185
-e MYSQL_HOST=mysql \
175186
-e MYSQL_USER=root \
@@ -179,6 +190,20 @@ With all of that explained, let's start our dev-ready container!
179190
sh -c "yarn install && yarn run dev"
180191
```
181192

193+
If you are using PowerShell then use this command.
194+
195+
```powershell hl_lines="3 4 5 6 7"
196+
docker run -dp 3000:3000 `
197+
-w /app -v "$(pwd):/app" `
198+
--network todo-app `
199+
-e MYSQL_HOST=mysql `
200+
-e MYSQL_USER=root `
201+
-e MYSQL_PASSWORD=secret `
202+
-e MYSQL_DB=todos `
203+
node:12-alpine `
204+
sh -c "yarn install && yarn run dev"
205+
```
206+
182207
1. If we look at the logs for the container (`docker logs <container-id>`), we should see a message indicating it's
183208
using the mysql database.
184209

docs/tutorial/using-bind-mounts/index.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,27 @@ So, let's do it!
3636

3737
1. Make sure you don't have any previous `getting-started` containers running.
3838

39-
1. Run the following command (replace the ` \ ` characters with `` ` `` in Windows PowerShell). We'll explain what's going on afterwards:
39+
1. Run the following command. We'll explain what's going on afterwards:
4040

4141
```bash
4242
docker run -dp 3000:3000 \
43-
-w /app -v ${PWD}:/app \
43+
-w /app -v "$(pwd):/app" \
4444
node:12-alpine \
4545
sh -c "yarn install && yarn run dev"
4646
```
4747

48+
If you are using PowerShell then use this command.
49+
50+
```powershell
51+
docker run -dp 3000:3000 `
52+
-w /app -v "$(pwd):/app" `
53+
node:12-alpine `
54+
sh -c "yarn install && yarn run dev"
55+
```
56+
4857
- `-dp 3000:3000` - same as before. Run in detached (background) mode and create a port mapping
4958
- `-w /app` - sets the "working directory" or the current directory that the command will run from
50-
- `-v ${PWD}:/app` - bind mount the current directory from the host in the container into the `/app` directory
59+
- `-v "$(pwd):/app"` - bind mount the current directory from the host in the container into the `/app` directory
5160
- `node:12-alpine` - the image to use. Note that this is the base image for our app from the Dockerfile
5261
- `sh -c "yarn install && yarn run dev"` - the command. We're starting a shell using `sh` (alpine doesn't have `bash`) and
5362
running `yarn install` to install _all_ dependencies and then running `yarn run dev`. If we look in the `package.json`,

docs/tutorial/using-docker-compose/index.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ And now, we'll start migrating a service at a time into the compose file.
4949
5050
## Defining the App Service
5151
52-
To remember, this was the command we were using to define our app container (replace the ` \ ` characters with `` ` `` in Windows PowerShell).
52+
To remember, this was the command we were using to define our app container.
5353
5454
```bash
5555
docker run -dp 3000:3000 \
56-
-w /app -v ${PWD}:/app \
56+
-w /app -v "$(pwd):/app" \
5757
--network todo-app \
5858
-e MYSQL_HOST=mysql \
5959
-e MYSQL_USER=root \
@@ -63,6 +63,20 @@ docker run -dp 3000:3000 \
6363
sh -c "yarn install && yarn run dev"
6464
```
6565

66+
If you are using PowerShell then use this command.
67+
68+
```powershell
69+
docker run -dp 3000:3000 `
70+
-w /app -v "$(pwd):/app" `
71+
--network todo-app `
72+
-e MYSQL_HOST=mysql `
73+
-e MYSQL_USER=root `
74+
-e MYSQL_PASSWORD=secret `
75+
-e MYSQL_DB=todos `
76+
node:12-alpine `
77+
sh -c "yarn install && yarn run dev"
78+
```
79+
6680
1. First, let's define the service entry and the image for the container. We can pick any name for the service.
6781
The name will automatically become a network alias, which will be useful when defining our MySQL service.
6882

@@ -102,7 +116,7 @@ docker run -dp 3000:3000 \
102116
- 3000:3000
103117
```
104118

105-
1. Next, we'll migrate both the working directory (`-w /app`) and the volume mapping (`-v ${PWD}:/app`) by using
119+
1. Next, we'll migrate both the working directory (`-w /app`) and the volume mapping (`-v "$(pwd):/app"`) by using
106120
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.
107121

108122
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 \
145159

146160
### Defining the MySQL Service
147161

148-
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):
162+
Now, it's time to define the MySQL service. The command that we used for that container was the following:
149163

150164
```bash
151165
docker run -d \
@@ -156,6 +170,17 @@ docker run -d \
156170
mysql:5.7
157171
```
158172

173+
If you are using PowerShell then use this command.
174+
175+
```powershell
176+
docker run -d `
177+
--network todo-app --network-alias mysql `
178+
-v todo-mysql-data:/var/lib/mysql `
179+
-e MYSQL_ROOT_PASSWORD=secret `
180+
-e MYSQL_DATABASE=todos `
181+
mysql:5.7
182+
```
183+
159184
1. We will first define the new service and name it `mysql` so it automatically gets the network alias. We'll
160185
go ahead and specify the image to use as well.
161186

0 commit comments

Comments
 (0)