Quoting from the Official Website:
Make sure you don’t have any previous getting-started containers running.
Run the following command from the app directory.
x86-64 Mac or Linux device:
docker run -dp 3000:3000 \
-w /app -v "$(pwd):/app" \
node:12-alpine \
sh -c "yarn install && yarn run dev"
docker run -dp 3000:3000 \ -w /app -v "$(pwd):/app" \ node:12-alpine \ sh -c "yarn install && yarn run dev"Windows (PowerShell):
docker run -dp 3000:3000 `
-w /app -v "$(pwd):/app" `
node:12-alpine `
sh -c "yarn install && yarn run dev"
docker run -dp 3000:3000 \ -w /app -v "$(pwd):/app" \ node:12-alpine \ sh -c "yarn install && yarn run dev"Aple silicon Mac or another ARM64 device:
docker run -dp 3000:3000 \
-w /app -v "$(pwd):/app" \
node:12-alpine \
sh -c "apk add --no-cache python2 g++ make && yarn install && yarn run dev"
docker run -dp 3000:3000 \\ -w /app -v "$(pwd):/app" \\ node:12-alpine \\ sh -c "apk add --no-cache python2 g++ make && yarn install && yarn run dev"
Explaining:
- dp 3000:3000
dp 3000:3000- same as before. Run in detached (background) mode and create a port mapping - w /app
w /app- sets the “working directory” or the current directory that the command will run from - v "$(pwd):/app"
v "$(pwd):/app"- bind mount the current directory from the host into the /app directory in the container - node:12-alpine
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"Dockerfile sh -c "yarn install && yarn run dev" - the command.
We’re starting a shell using shsh (alpine doesn’t have bashBash) and running yarn installyarn install to install all dependencies and then running yarn run devrun dev. If we look in the package.jsonpackage.json, we’ll see that the dev script is starting nodemonnodemon.