GithubHelp home page GithubHelp logo

claclacla / microservices-from-development-to-production-using-docker-compose-and-docker-swarm Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3 KB

The multi environment workflow of an application architecture

License: MIT License

docker docker-compose docker-machine devops microservices

microservices-from-development-to-production-using-docker-compose-and-docker-swarm's Introduction

Microservices from development to production using Docker Swarm

Compose and deploy the application infrastructure


Prerequisites

What things you need to install the software

docker 18+
docker-compose 1.20.1+
docker-machine 0.14.0+


Development

# Move to the docker/dev folder
cd docker/dev

# Create a .env file with your local absolute path to the application folder
echo "APP_FOLDER=/your-path-to-the/application-folder" > .env

# Compose the docker containers
sudo docker-compose up -d

Production

Create the services image and push it to the Docker Hub repository

# Move to the project main folder
cd /your-path-to-the/application-folder

# Build the docker image
docker build -f docker/production/Dockerfile . -t <username>/<application name>

# Define the organization user ID
export DOCKER_ID_USER=username

# Login with your Docker data
docker login

# Push the application image to the DockerHub
docker push <username>/<application name>

Create the Docker cluster

# Create the docker machines
docker-machine create --driver=virtualbox NodeManager
docker-machine create --driver=virtualbox NodeWorker1

# Use the following command to read the manager ip
docker-machine ls

# Instruct the manager to become a swarm manager
docker-machine ssh NodeManager "docker swarm init --advertise-addr <manager ip>"

# The response will look like this:

# Swarm initialized: current node (q4udo31nbhfp1zsi9h8bzfkgm) is now a manager.
#
# To add a worker to this swarm, run the following command:
#
#    docker swarm join --token SWMTKN-1-3mprdn0gjmijoauacc2m20ezanhpst3m8j3lfb7a3fkc4fwzri-48uizyf8dwuo7mrm3zanqd2ll 192.168.99.100:2377
#
# To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

# Use the command above to have worker1 join the swarm 
docker-machine ssh NodeWorker1 "docker swarm join --token <token> <ip>:2377"

# Use this command to control the swarm status
docker-machine ssh NodeManager "docker node ls"

Deploy the app to the Docker cluster

# Get the command to talk with NodeManager
docker-machine env NodeManager

# The response will look like this:

# export DOCKER_TLS_VERIFY="1"
# export DOCKER_HOST="tcp://192.168.99.100:2376"
# export DOCKER_CERT_PATH="/root/.docker/machine/machines/NodeManager"
# export DOCKER_MACHINE_NAME="NodeManager"
# # Run this command to configure your shell: 
# # eval $(docker-machine env NodeManager)

# Use the previous command to configure the shell
eval $(docker-machine env NodeManager)

# Use the following command to verify your shell
docker node ls

# Go to the docker production folder
cd docker/production

# Use the following command to deploy the app
docker stack deploy --with-registry-auth -c docker-compose.yaml App

# Check the stack status
docker stack ps App

# Check the processes status
docker service ls

# Show the process logs
docker service logs <service name> --raw

# If needed remove the stack
docker stack rm NodeApp

Authors


License

This project is licensed under the MIT License


Acknowledgments

microservices-from-development-to-production-using-docker-compose-and-docker-swarm's People

Contributors

claclacla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.