有没有一种方法可以将frondend和后端容器(分开)组合成一个docker镜像?

时间:2019-05-29 14:20:45

标签: web-applications docker-compose docker-image

因此,我有五个不同的容器,分别用于elasticsearch,kibana,后端(节点),前端(反应)和mongo。 我想要的是为我的应用程序构建一个单个图像。前端部分可以分开放置。

我的docker-compose.yml

version: "3"

services:
  ##########################
  ### SETUP SERVER CONTAINER
  ##########################
  server:
    container_name: nbserver
    # Tell docker what file to build the server from
    build:
      context: ./server
      dockerfile: Dockerfile-dev
    # The ports to expose
    expose:
      - 3001
    # Environment variables
    environment:
      - MONGO_URI=mongodb://db:27017/db
      - PORT=4000
      - DEBUG=worker:*
      - MORGAN=combined
      - NODE_ENV=development
    # Port mapping
    ports:
      - 3001:3001
    # Volumes to mount
    volumes:
      - ./server:/app/server
    # Run command
    # Nodemon for hot reloading (-L flag required for polling in Docker)
    command: nodemon -L ./server.js
    # Connect to other containers
    links:
      - db
      - elasticsearch
      - kibana
    # Restart action
    restart: always
  ##########################
  ### SETUP CLIENT CONTAINER
  ##########################
  client:
    container_name: nbclient
    build:
      context: ./client
      dockerfile: Dockerfile-dev
    environment:
      - REACT_APP_PORT=3000
      - CHOKIDAR_USEPOLLING=true
    expose:
      - 3000
    ports:
      - 3000:3000
    volumes:
      - ./client/src:/app/client/src
      - ./client/public:/app/client/public
    links:
      - server
    command: npm run start
    restart: always

  ##########################
  ### SETUP DB CONTAINER
  ##########################
  db:
    container_name: nbmongo
    image: mongo
    ports:
      - 27017:27017
    restart: always

  ##########################
  ### SETUP ELASTIC SEARCH
  ##########################
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.6.16
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "xpack.security.enabled=false"
    volumes:
      - esdata:/usr/share/elasticsearch/data
    ulimits:
      memlock:
        soft: -1
        hard: -1
    ports:
        - "9200:9200"

  ##########################
  ### SETUP KIBANA
  ##########################
  kibana:
    image: docker.elastic.co/kibana/kibana:5.6.16
    ports:
      - "5601:5601"
    environment:
      - "xpack.security.enabled=false"

volumes:
  esdata:

它非常适合开发。对于生产,我需要构建图像。这样,只需docker pull and run就可以满足并运行应用程序。

我对Docker来说还很陌生,因此文档非常丰富,可以介绍所有功能和可能性。我非常感谢您的帮助或某些资源关键字可以帮助您实现同样的目的:)

0 个答案:

没有答案