Steps to Deploy Node-Express-Boilerplate

Follow these steps to deploy node-express-boilerplate:

  1. Install docker

  2. Prepare 3 hosts

    Screenshot 2023-07-26 at 15.09.21.png

  3. Open protocols and ports between the hosts(Ubuntu). The following ports must be available. On some systems, these ports are open by default.

  1. Create a swarm
docker swarm init
  1. Add nodes to the swarm Connect to these other hosts to add that node to the manager swarm We call these other hosts may be: “worker1”, “worker2” By TOKEN when create swarm

    docker swarm join --token <TOKEN> <MANGER_IP>:2377
    
  2. Clone the repository:

    git clone <https://github.com/AnhtuanUit/node-express-boilerplate>
    
    
  3. Go to the source code

    cd node-express-boilerplate
    
    
  4. Set environment variables:

    cp .env.example .env
    
    

    Update .env with your own environment variables. Note: make sure you prepare the .env file before you run the docker scripts because the .env will be copied to Docker Image the first time run the docker scripts.

  5. Install docker-compose to test the docker-compose.yml file first

    All in one command 😛

    sudo curl -L "<https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$>(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
    docker-compose --version
    
  6. Test docker-compose.yml file (for swarm mode deploy stack services)

    docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.swarm.yml up
    
    
  7. Check that the app is running with docker-compose ps:

    docker-compose ps
    

    You can test the app with curl:

    curl <http://localhost:3000>
    curl <http://localhost:27017>
    
  8. Bring the app down:

    docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.swarm.yml down -d
    
  9. Set up a Docker registry

    docker service create --name registry --publish published=5000,target=5000 registry:2