1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How can I create multiple images of the same application in Docker with Multiple dynamic...

Discussão em 'Angular' iniciado por Rakesh Bakoriya, Outubro 5, 2024.

  1. Here is working for me, I have deployed 10 different domains with different databases on a single instance

    I have used ROR in the backend and Angular in the front end

    Example for domain_1

    • Domain: domain_1.com
    • Database: domain_1

    Example for domain_2

    • Domain: domain_2.com
    • Database: domain_2

    Backend-app:

    Dockerfile:

    FROM ruby:2.3
    LABEL maintainer=" maintainer name <maintainer@gmail.co>"

    # Install dependencies
    RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

    # Set an environment variable where the Rails app is installed to inside of Docker image:
    ENV RAILS_ROOT /var/www/domain_1
    RUN mkdir -p $RAILS_ROOT/app
    RUN mkdir -p $RAILS_ROOT/shared
    RUN mkdir -p $RAILS_ROOT/shared/tmp/sockets
    RUN mkdir -p $RAILS_ROOT/shared/tmp/pids

    # Set working directory, where the commands will be ran:
    WORKDIR $RAILS_ROOT/app

    # Setting env up
    ENV RAILS_ENV='production'
    ENV RACK_ENV='production'
    ENV SHARED_DIR=$RAILS_ROOT/shared
    ENV DATABASE_NAME=domain_1
    ENV DATABASE_CONFIG=$RAILS_ROOT/app/config/database.yml
    ENV HOST="https://domain_1.com"
    ENV BIND_ADDR="tcp:127.0.0.1:3000"
    ENV BASEURL="https://domain_1.com"
    ENV FRONTEND_URL="https://domain_1.com"

    # Adding gems
    COPY Gemfile Gemfile
    COPY Gemfile.lock Gemfile.lock
    RUN bundle install --jobs 20 --retry 5

    # Adding project files
    COPY . .
    RUN ["chmod", "+x", "./docker-entrypoint.sh"]

    EXPOSE 9191

    ENTRYPOINT ["./docker-entrypoint.sh"]


    docker-compose.yml:

    version: '3.2'
    services:
    db:
    image: postgres
    ports:
    - "5432:5432"

    domain_1_web:
    image: domain_1_web
    build:
    context: .
    dockerfile: ./docker/domain_1/Dockerfile
    extra_hosts:
    - "localhost:127.0.0.1"
    environment:
    - SHARED_DIR=/var/www/domain_1/shared
    - BIND_ADDR=tcp://0.0.0.0:9191
    ports:
    - "9191:9191"
    stdin_open: true
    tty: true
    depends_on:
    - db
    volumes:
    - type: volume
    source: db-data
    target: /var/www/domain_1/app/uploads
    volume:
    nocopy: true
    - type: bind
    source: /var/www/domain_1/app/public/uploads
    target: /var/www/domain_1/app/public/uploads
    domain_1_node:
    image: domain_1_node
    build:
    context: ../frontend-app/
    dockerfile: ./docker/domain_1/Dockerfile
    ports:
    - 9001:9001
    stdin_open: true
    tty: true

    domain_2_web:
    image: domain_2_web
    build:
    context: .
    dockerfile: ./docker/domain_2/Dockerfile
    extra_hosts:
    - "localhost:127.0.0.1"
    environment:
    - SHARED_DIR=/var/www/domain_2/shared
    - BIND_ADDR=tcp://0.0.0.0:9292
    ports:
    - "9292:9292"
    stdin_open: true
    tty: true
    depends_on:
    - db
    volumes:
    - type: volume
    source: db-data
    target: /var/www/domain_2/app/uploads
    volume:
    nocopy: true
    - type: bind
    source: /var/www/domain_2/app/public/uploads
    target: /var/www/domain_2/app/public/uploads
    domain_2_node:
    image: domain_2_node
    build:
    context: ../frontend-app/
    dockerfile: ./docker/domain_2/Dockerfile
    ports:
    - 9002:9002
    stdin_open: true
    tty: true
    volumes:
    db-data:


    frontend-app:

    Dockerfile:

    # Stage 1: Compile and Build angular codebase

    # Use the official node image as the base image
    FROM node:10

    # Set the ENV variable
    ENV NODE_ROOT /var/www/domain_1/
    ENV API_URL "https://domain_1.com"
    ENV PORT 9001

    RUN mkdir -p $NODE_ROOT/frontend-app

    # Working DIR
    WORKDIR $NODE_ROOT/frontend-app

    COPY package*.json $NODE_ROOT/frontend-app/
    COPY angular*.json $NODE_ROOT/frontend-app/

    # Install node packages
    RUN npm install
    RUN npm i ng-multiselect-dropdown@0.3.1

    # Copy folder
    COPY ./ $NODE_ROOT/frontend-app/
    COPY ./docker/domain_1/environment.prod.ts $NODE_ROOT/frontend-app/src/environments/environment.prod.ts

    # Generate the build of the application
    RUN node --max_old_space_size=9048 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer

    # Expose port
    EXPOSE 9001

    # Run application
    CMD ["node", "server.js"]


    environment.prod.ts:

    export const environment = {
    production: true,
    apiUrl: 'https://domain_1.com'
    };


    Nginix:

    domain_1.conf:

    upstream domain_1_backend_app {
    server 0.0.0.0:9191;
    }


    upstream domain_1_frontend_app {
    server 0.0.0.0:9001;
    }

    server {
    server_name domain_1.com;

    try_files $uri/index.html $uri @domain_1_backend_app;


    location ~ ^/v1/ {
    proxy_pass http://domain_1_backend_app;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_connect_timeout 43200000;
    proxy_read_timeout 43200000;
    proxy_send_timeout 43200000;

    }
    location / {
    proxy_pass http://domain_1_frontend_app;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_connect_timeout 43200000;
    proxy_read_timeout 43200000;
    proxy_send_timeout 43200000;
    }
    location /uploads/ {
    alias /var/www/domain_1/app/public/uploads/;
    }


    error_page 500 502 503 504 /500.html;
    client_max_body_size 4G;
    proxy_max_temp_file_size 0;
    keepalive_timeout 10;



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain_1.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain_1.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    }

    Continue reading...

Compartilhe esta Página