D
D
Dos2019-11-20 02:58:39
Node.js
Dos, 2019-11-20 02:58:39

How to use Nuxt in Docker?

I'm trying to set up docker and nuxt to work in development and production modes. Please tell me how to properly set up my project so that I can quickly switch between modes.
My services:

docker-compose.yml

version: '3'
services:
    frontend-nginx:
        build:
            context: ./frontend/docker
            dockerfile: nginx.docker
        volumes:
            - ./frontend:/frontend
        depends_on:
            - manager-php-fpm
    frontend-nodejs:
        image: node:10.11-jessie
        command: npm run dev
        volumes:
            - ./frontend:/frontend
        working_dir: /frontend
        ports:
          - "3000:3000"
        environment:
          HOST: 0.0.0.0
        tty: true


config

server {
    listen 80
    location / {
        proxy_pass http://frontend-nodejs:3000;
    }
}


I run the command through makefile
frontend-init: frontend-install
frontend-install:
  docker-compose exec frontend-nodejs npm install

With this configuration, I managed to configure only the version that does not respond to changes during development. It seems that the command is used by dev, but nothing changes...
I understand that you need to use two configs: docker-dev/docker-prod and nginx/dev nginx/prod
But I can't figure out how to configure both correctly for two modes? Can you help? Where to read? How to develop in docker with nodejs? Maybe for development it is not needed at all? Tell.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2019-11-20
@pro-dev

I understand that you need to use two configs: docker-dev/docker-prod and nginx/dev nginx/prod
But I can't figure out how to configure both correctly for two modes? Can you help?

I give an example
Development configuration
# Development configuration
version: "3.1"

services:

  # Php application
  app:
    container_name: cc.app
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile-dev
    restart: on-failure
    volumes:
      - .:/www
      - ./docker/php/log:/var/log
      - ./docker/php/usr/local/etc/php/conf.d:/usr/local/etc/php/conf.d
    depends_on:
      - db
    links:
      - db
    expose:
      - 9000
    environment:
      PHP_INI_SCAN_DIR: ":/usr/local/etc/php/conf.d"


  # Database
  db:
    image: percona:latest
    container_name: cc.db
    restart: on-failure
    ports:
      - 127.0.0.160:3306:3306
    expose:
      - 3306
    environment:
      - MYSQL_ROOT_PASSWORD=rk3kw1UDdqOEF4L1pmNkcyQ2oL
      - MYSQL_DATABASE=cc
      - MYSQL_ROOT_HOST=%



  # Nginx api server
  nginx-api:
    container_name: cc.nginx-api
    image: nginx:latest
    restart: on-failure
    volumes:
      - ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/dev/sites-enabled/vhost-api.conf:/etc/nginx/sites-enabled/vhost-api.conf
    ports:
      - 127.0.0.160:8090:80
    depends_on:
      - app
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]



  # Nginx admin server
  nginx-admin:
    container_name: cc.nginx-admin
    image: nginx:latest
    restart: on-failure
    volumes:
      - ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/dev/sites-enabled/vhost-admin.conf:/etc/nginx/sites-enabled/vhost-admin.conf
    ports:
      - 127.0.0.160:8091:80
    depends_on:
      - app
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]


  # Nginx secure server
  nginx-secure:
    container_name: cc.nginx-secure
    image: nginx:latest
    restart: on-failure
    volumes:
      - ./docker/nginx/dev/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/dev/sites-enabled/vhost-secure.conf:/etc/nginx/sites-enabled/vhost-secure.conf
    ports:
      - 127.0.0.160:8092:80
    depends_on:
      - app
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]

production configuration
# Production configuration
version: "3.1"

services:

  # Php application
  app:
    container_name: ruintouch.app
    restart: always
    build:
      context: .
      dockerfile: ./docker/php/Dockerfile-prod
    expose:
      - 9000



  # Nginx api server
  nginx-api:
    container_name: ruintouch.nginx-api
    image: nginx:latest
    restart: always
    volumes:
      - ./docker/nginx/prod/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/prod/sites-enabled/vhost-api.conf:/etc/nginx/sites-enabled/vhost-api.conf
    ports:
      - 8095:80
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]



  # Nginx admin server
  nginx-admin:
    container_name: ruintouch.nginx-admin
    image: nginx:latest
    restart: always
    volumes:
      - ./docker/nginx/prod/nginx.conf:/etc/nginx/nginx.conf
      - ./docker/nginx/prod/sites-enabled/vhost-admin.conf:/etc/nginx/sites-enabled/vhost-admin.conf
    ports:
      - 8096:80
    expose:
      - 80
    command: ["nginx", "-g", "daemon off;"]



      #Nuxt publication
  nuxt-public:
    container_name: ruintouch.nuxt_public
    restart: always
    build:
      context: ./nuxt_public
      dockerfile: Dockerfile-prod
    ports:
      - "3001:3000"
    expose:
      - "3000"

With "vue hot reload in docker" alas ((

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question