Prerequisites:
- Docker Create virtual machines and Swarm
- How to use Docker Create a node. js The development Environment
Body:
?
- How to use Docker to build a node. JS Development Environment The Nodehello image created in the article is published on the official website.
Perform Docker images to list all current image. Perform Docker login Login Tag Nodehello Image: Docker Tag Image Username/repository:tag For example: docker tag nodehello john/get-started:part2
Publish Image: docker push username/repository:tag
For example: docker push nodehello john/get-started:part2
The purpose of the release is to be able to access in the virtual machine, if directly with the name of the image on the host machine, the virtual machine may not be accessible. |
?
- How to Build a node. JS Development environment with Docker Create a file named Docker-stack.yml in the directory that you are targeting in.
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: username/repo:tag
deploy:
replicas: 5
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.1"
memory: 50M
ports:
- "3000:3000"
networks:
- webnet
|
?
Note that the image inside is best used to publish to the official website tag name, for example: John/get-started:part2, if directly with the host machine image name, virtual machine may not access.
- Run PowerShell as an administrator, and switch the directory to the directory in step 2, and then run the following command:
docker stack deploy -c <compose file> <stack name>
例如:
docker stack deploy -c docker-stack.yml getstartedlab_node
|
?
???? After running, you will be prompted that Getstartedlab_node_webnet and Getstartedlab_node_web have created a similar typeface.
- View the current service.
A successful deployment of the service will be listed, and the deployment of Getstartedlab_node_web should be displayed. If replica appears 0/5 similar words, do not worry, you can do this
Docker Service PS <service name> |
Then look at the CURRETN State column, if a similar preparing appears, stating that the service is ready to deploy, and then re-execute the command view. If a similar word running appears, the service is already started and can be accessed at this time.
?
- According to our configuration, access to HTTP://<MYVM1 ' s ip>:3000
It should be possible to see the results of our node. JS program output.
Docker: How to deploy a node. JS project to Docker's swarm