Home Explore Blog CI



docker

4th chunk of `content/get-started/workshop/06_bind_mounts.md`
6665d26a3e33e18f69c93ce6eaccce01adcfbf174e2296aa0000000100000fcc
   - `-w /app` - sets the "working directory" or the current directory that the
     command will run from
   - `--mount "type=bind,src=$pwd,target=/app"` - bind mount the current
     directory from the host into the `/app` directory in the container
   - `node:18-alpine` - the image to use. Note that this is the base image for
     your app from the Dockerfile
   - `sh -c "yarn install && yarn run dev"` - the command. You're starting a
     shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
     install packages and then running `yarn run dev` to start the development
     server. If you look in the `package.json`, you'll see that the `dev` script
     starts `nodemon`.

3. You can watch the logs using `docker logs <container-id>`. You'll know you're
   ready to go when you see this:

   ```console
   $ docker logs -f <container-id>
   nodemon -L src/index.js
   [nodemon] 2.0.20
   [nodemon] to restart at any time, enter `rs`
   [nodemon] watching path(s): *.*
   [nodemon] watching extensions: js,mjs,json
   [nodemon] starting `node src/index.js`
   Using sqlite database at /etc/todos/todo.db
   Listening on port 3000
   ```

   When you're done watching the logs, exit out by hitting `Ctrl`+`C`.

{{< /tab >}}
{{< tab name="Command Prompt CLI" >}}

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

2. Run the following command from the `getting-started-app` directory.

   ```console
   $ docker run -dp 127.0.0.1:3000:3000 ^
       -w /app --mount "type=bind,src=%cd%,target=/app" ^
       node:18-alpine ^
       sh -c "yarn install && yarn run dev"
   ```

   The following is a breakdown of the command:
   - `-dp 127.0.0.1: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
   - `--mount "type=bind,src=%cd%,target=/app"` - bind mount the current
     directory from the host into the `/app` directory in the container
   - `node:18-alpine` - the image to use. Note that this is the base image for
     your app from the Dockerfile
   - `sh -c "yarn install && yarn run dev"` - the command. You're starting a
     shell using `sh` (alpine doesn't have `bash`) and running `yarn install` to
     install packages and then running `yarn run dev` to start the development
     server. If you look in the `package.json`, you'll see that the `dev` script
     starts `nodemon`.

3. You can watch the logs using `docker logs <container-id>`. You'll know you're
   ready to go when you see this:

   ```console
   $ docker logs -f <container-id>
   nodemon -L src/index.js
   [nodemon] 2.0.20
   [nodemon] to restart at any time, enter `rs`
   [nodemon] watching path(s): *.*
   [nodemon] watching extensions: js,mjs,json
   [nodemon] starting `node src/index.js`
   Using sqlite database at /etc/todos/todo.db
   Listening on port 3000
   ```

   When you're done watching the logs, exit out by hitting `Ctrl`+`C`.

{{< /tab >}}
{{< tab name="Git Bash CLI" >}}

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

2. Run the following command from the `getting-started-app` directory.

   ```console
   $ docker run -dp 127.0.0.1:3000:3000 \
       -w //app --mount type=bind,src="/$(pwd)",target=/app \
       node:18-alpine \
       sh -c "yarn install && yarn run dev"
   ```

   The following is a breakdown of the command:
   - `-dp 127.0.0.1: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
   - `--mount type=bind,src="/$(pwd)",target=/app` - bind mount the current
     directory from the host into the `/app` directory in the container
   - `node:18-alpine` - the image to use. Note that this is the base image for
     your app from the Dockerfile
   - `sh -c "yarn install && yarn run dev"` - the command. You're starting a

Title: Running a Development Container with Bind Mounts (CLI) - Continued
Summary
This section continues the instructions on running a development container with bind mounts using the CLI, focusing on Command Prompt and Git Bash environments. It provides the specific `docker run` commands for each, explaining how they mount the current directory into the container, install dependencies using `yarn`, and start the development server with `nodemon`. It also details how to monitor the container's logs to ensure the application is running correctly and how to exit the logs.