Install the Docker
See the official documentation, ^_^
Create a Docker container
Write a Dockerfile file
FROM node:12-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
Copy the code
Create an image file
docker build -t getting-started .
Copy the code
-t
: used to specifyimage
The name of the file, followed by a colon to specify the label. If not specified, the default label islatest
Generated container
The docker run command generates containers from the image file
docker run -dp 8000:3000 getting-started
Copy the code
-d
: Lets the container run in the background-p
: Map the network port 3000 used internally by the container to port 8000 used by our host so that our application can run locally
Next, run localhost:8000 in your browser and you can see our application
reference
- Docker Guides
- Docker tutorial
- Docker rookie tutorial