Docker: How to deploy a node. JS project to Docker's swarm

Source: Internet
Author: User
Tags tag name

Prerequisites:
    1. Docker Create virtual machines and Swarm
    2. How to use Docker Create a node. js The development Environment
Body:

?

    1. 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.

?

    1. 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.

    1. 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.

    1. View the current service.

Docker Service ls

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.

?

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.