From f77065be98434cd8209ac28d5495f4bed2ca4b34 Mon Sep 17 00:00:00 2001 From: Stefan Scherer Date: Wed, 15 Jul 2020 08:04:40 +0200 Subject: [PATCH 1/2] Show multiline PowerShell commands Signed-off-by: Stefan Scherer --- docs/tutorial/multi-container-apps/index.md | 29 +++++++++++++++++++-- docs/tutorial/using-bind-mounts/index.md | 11 +++++++- docs/tutorial/using-docker-compose/index.md | 29 +++++++++++++++++++-- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/docs/tutorial/multi-container-apps/index.md b/docs/tutorial/multi-container-apps/index.md index 00894a1..59d2c49 100644 --- a/docs/tutorial/multi-container-apps/index.md +++ b/docs/tutorial/multi-container-apps/index.md @@ -38,7 +38,7 @@ For now, we will create the network first and attach the MySQL container at star ``` 1. Start a MySQL container and attach it the network. We're also going to define a few environment variables that the - 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). + database will use to initialize the database (see the "Environment Variables" section in the [MySQL Docker Hub listing](https://hub.docker.com/_/mysql/)). ```bash docker run -d \ @@ -49,6 +49,17 @@ For now, we will create the network first and attach the MySQL container at star 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 + ``` + You'll also see we specified the `--network-alias` flag. We'll come back to that in just a moment. !!! info "Pro-tip" @@ -165,7 +176,7 @@ The todo app supports the setting of a few environment variables to specify MySQ With all of that explained, let's start our dev-ready container! -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). +1. We'll specify each of the environment variables above, as well as connect the container to our app network. ```bash hl_lines="3 4 5 6 7" docker run -dp 3000:3000 \ @@ -179,6 +190,20 @@ With all of that explained, let's start our dev-ready container! sh -c "yarn install && yarn run dev" ``` + If you are using PowerShell then use this command. + + ```powershell hl_lines="3 4 5 6 7" + 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. If we look at the logs for the container (`docker logs `), we should see a message indicating it's using the mysql database. diff --git a/docs/tutorial/using-bind-mounts/index.md b/docs/tutorial/using-bind-mounts/index.md index 9512571..9b714e7 100644 --- a/docs/tutorial/using-bind-mounts/index.md +++ b/docs/tutorial/using-bind-mounts/index.md @@ -36,7 +36,7 @@ So, let's do it! 1. Make sure you don't have any previous `getting-started` containers running. -1. Run the following command (replace the ` \ ` characters with `` ` `` in Windows PowerShell). We'll explain what's going on afterwards: +1. Run the following command. We'll explain what's going on afterwards: ```bash docker run -dp 3000:3000 \ @@ -45,6 +45,15 @@ So, let's do it! 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 ` + node:12-alpine ` + sh -c "yarn install && yarn run dev" + ``` + - `-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 - `-v ${PWD}:/app` - bind mount the current directory from the host in the container into the `/app` directory diff --git a/docs/tutorial/using-docker-compose/index.md b/docs/tutorial/using-docker-compose/index.md index 672d08f..568302a 100644 --- a/docs/tutorial/using-docker-compose/index.md +++ b/docs/tutorial/using-docker-compose/index.md @@ -49,7 +49,7 @@ 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 \ @@ -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. @@ -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. From a33ed89ab3ca413fadeac864fa1fdce949625314 Mon Sep 17 00:00:00 2001 From: Stefan Scherer Date: Wed, 15 Jul 2020 08:45:25 +0200 Subject: [PATCH 2/2] Quote volume mapping and use pwd Signed-off-by: Stefan Scherer --- docs/tutorial/multi-container-apps/index.md | 4 ++-- docs/tutorial/using-bind-mounts/index.md | 6 +++--- docs/tutorial/using-docker-compose/index.md | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/tutorial/multi-container-apps/index.md b/docs/tutorial/multi-container-apps/index.md index 59d2c49..d400835 100644 --- a/docs/tutorial/multi-container-apps/index.md +++ b/docs/tutorial/multi-container-apps/index.md @@ -180,7 +180,7 @@ With all of that explained, let's start our dev-ready container! ```bash hl_lines="3 4 5 6 7" 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 \ @@ -194,7 +194,7 @@ With all of that explained, let's start our dev-ready container! ```powershell hl_lines="3 4 5 6 7" 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 ` diff --git a/docs/tutorial/using-bind-mounts/index.md b/docs/tutorial/using-bind-mounts/index.md index 9b714e7..072f32c 100644 --- a/docs/tutorial/using-bind-mounts/index.md +++ b/docs/tutorial/using-bind-mounts/index.md @@ -40,7 +40,7 @@ So, let's do it! ```bash docker run -dp 3000:3000 \ - -w /app -v ${PWD}:/app \ + -w /app -v "$(pwd):/app" \ node:12-alpine \ sh -c "yarn install && yarn run dev" ``` @@ -49,14 +49,14 @@ So, let's do it! ```powershell docker run -dp 3000:3000 ` - -w /app -v ${PWD}:/app ` + -w /app -v "$(pwd):/app" ` node:12-alpine ` sh -c "yarn install && yarn run dev" ``` - `-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 - - `-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 - `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`, diff --git a/docs/tutorial/using-docker-compose/index.md b/docs/tutorial/using-docker-compose/index.md index 568302a..9927500 100644 --- a/docs/tutorial/using-docker-compose/index.md +++ b/docs/tutorial/using-docker-compose/index.md @@ -53,7 +53,7 @@ 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 \ @@ -67,7 +67,7 @@ If you are using PowerShell then use this command. ```powershell 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 ` @@ -116,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.