Quote volume mapping and use pwd
Signed-off-by: Stefan Scherer <stefan.scherer@docker.com>
This commit is contained in:
parent
f77065be98
commit
a33ed89ab3
@ -180,7 +180,7 @@ With all of that explained, let's start our dev-ready container!
|
|||||||
|
|
||||||
```bash hl_lines="3 4 5 6 7"
|
```bash hl_lines="3 4 5 6 7"
|
||||||
docker run -dp 3000:3000 \
|
docker run -dp 3000:3000 \
|
||||||
-w /app -v ${PWD}:/app \
|
-w /app -v "$(pwd):/app" \
|
||||||
--network todo-app \
|
--network todo-app \
|
||||||
-e MYSQL_HOST=mysql \
|
-e MYSQL_HOST=mysql \
|
||||||
-e MYSQL_USER=root \
|
-e MYSQL_USER=root \
|
||||||
@ -194,7 +194,7 @@ With all of that explained, let's start our dev-ready container!
|
|||||||
|
|
||||||
```powershell hl_lines="3 4 5 6 7"
|
```powershell hl_lines="3 4 5 6 7"
|
||||||
docker run -dp 3000:3000 `
|
docker run -dp 3000:3000 `
|
||||||
-w /app -v ${PWD}:/app `
|
-w /app -v "$(pwd):/app" `
|
||||||
--network todo-app `
|
--network todo-app `
|
||||||
-e MYSQL_HOST=mysql `
|
-e MYSQL_HOST=mysql `
|
||||||
-e MYSQL_USER=root `
|
-e MYSQL_USER=root `
|
||||||
|
@ -40,7 +40,7 @@ So, let's do it!
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -dp 3000:3000 \
|
docker run -dp 3000:3000 \
|
||||||
-w /app -v ${PWD}:/app \
|
-w /app -v "$(pwd):/app" \
|
||||||
node:12-alpine \
|
node:12-alpine \
|
||||||
sh -c "yarn install && yarn run dev"
|
sh -c "yarn install && yarn run dev"
|
||||||
```
|
```
|
||||||
@ -49,14 +49,14 @@ So, let's do it!
|
|||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
docker run -dp 3000:3000 `
|
docker run -dp 3000:3000 `
|
||||||
-w /app -v ${PWD}:/app `
|
-w /app -v "$(pwd):/app" `
|
||||||
node:12-alpine `
|
node:12-alpine `
|
||||||
sh -c "yarn install && yarn run dev"
|
sh -c "yarn install && yarn run dev"
|
||||||
```
|
```
|
||||||
|
|
||||||
- `-dp 3000:3000` - same as before. Run in detached (background) mode and create a port mapping
|
- `-dp 3000:3000` - same as before. Run in detached (background) mode and create a port mapping
|
||||||
- `-w /app` - sets the "working directory" or the current directory that the command will run from
|
- `-w /app` - sets the "working directory" or the current directory that the command will run from
|
||||||
- `-v ${PWD}:/app` - bind mount the current directory from the host in the container into the `/app` directory
|
- `-v "$(pwd):/app"` - bind mount the current directory from the host in the container into the `/app` directory
|
||||||
- `node:12-alpine` - the image to use. Note that this is the base image for our app from the Dockerfile
|
- `node:12-alpine` - the image to use. Note that this is the base image for our app from the Dockerfile
|
||||||
- `sh -c "yarn install && yarn run dev"` - the command. We're starting a shell using `sh` (alpine doesn't have `bash`) and
|
- `sh -c "yarn install && yarn run dev"` - the command. We're starting a shell using `sh` (alpine doesn't have `bash`) and
|
||||||
running `yarn install` to install _all_ dependencies and then running `yarn run dev`. If we look in the `package.json`,
|
running `yarn install` to install _all_ dependencies and then running `yarn run dev`. If we look in the `package.json`,
|
||||||
|
@ -53,7 +53,7 @@ To remember, this was the command we were using to define our app container.
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -dp 3000:3000 \
|
docker run -dp 3000:3000 \
|
||||||
-w /app -v ${PWD}:/app \
|
-w /app -v "$(pwd):/app" \
|
||||||
--network todo-app \
|
--network todo-app \
|
||||||
-e MYSQL_HOST=mysql \
|
-e MYSQL_HOST=mysql \
|
||||||
-e MYSQL_USER=root \
|
-e MYSQL_USER=root \
|
||||||
@ -67,7 +67,7 @@ If you are using PowerShell then use this command.
|
|||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
docker run -dp 3000:3000 `
|
docker run -dp 3000:3000 `
|
||||||
-w /app -v ${PWD}:/app `
|
-w /app -v "$(pwd):/app" `
|
||||||
--network todo-app `
|
--network todo-app `
|
||||||
-e MYSQL_HOST=mysql `
|
-e MYSQL_HOST=mysql `
|
||||||
-e MYSQL_USER=root `
|
-e MYSQL_USER=root `
|
||||||
@ -116,7 +116,7 @@ docker run -dp 3000:3000 `
|
|||||||
- 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.
|
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.
|
One advantage of Docker Compose volume definitions is we can use relative paths from the current directory.
|
||||||
|
Loading…
Reference in New Issue
Block a user