简体   繁体   English

如何正确地泊坞平均堆栈应用程序?

[英]How to properly dockerize a mean stack application?

I'm developing a mean stack application (running angular 6, not angular js). 我正在开发一个平均堆栈应用程序(运行angular 6,而不是angular js)。 I was asked to dockerise it, and since I'm not an expert in Docker, I was wondering what was the best choice : - Create seperate containers, one for the database, express app and angular app - Deploy the whole stack in a single container 我被要求对其进行dockerise,并且由于我不是Docker方面的专家,所以我想知道最佳选择是什么:-创建单独的容器,分别用于数据库,express应用程序和angular应用程序-将整个堆栈部署在单个容器中容器

running separate containers is the way to go and do it through docker-compose so you can spin up all the necessary containers just one single command 运行单独的容器是通过docker-compose进行操作的方法,因此您只需一个命令即可启动所有必需的容器

simple tutorial : https://codereviewvideos.com/course/docker-tutorial-for-beginners/video/docker-compose-tutorial 简单教程: https : //codereviewvideos.com/course/docker-tutorial-for-beginners/video/docker-compose-tutorial

Let me recommend you to use a container for each application: 让我建议您为每个应用程序使用一个容器:

  • 1 container for angular 1个角形容器
  • 1 container for app 1个用于应用程序的容器
  • 1 container for database. 1个用于数据库的容器。

Furthermore defining one Dockerfile for each one, you can define a docker-compose.yml which can build and deploy all of them. 此外,为每个文件定义一个Dockerfile,您可以定义一个docker-compose.yml ,该文件可以构建和部署所有文件。

Finally, in this docker-compose file you can mount volumes to store outside containers database data (for example: /var/lib/mysql for mysql db), because when container exits, all information new from container starting is lost. 最后,在此docker-compose文件中,您可以装入卷以存储外部容器的数据库数据(例如:/ var / lib / mysql用于mysql db),因为当容器退出时,所有容器启动中的新信息都将丢失。

Manage and define some ARGS / ENV for DB parameters. 管理和定义一些用于数据库参数的ARGS / ENV。

docker-compose.yml example: docker-compose.yml示例:

version: '3.6'

services: 
  mysql:
    container_name: your_db_container
    restart: always
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
      MYSQL_USER: 'test'
      MYSQL_PASS: 'pass'
    volumes:
      - /tmp/your_db_dir:/var/lib/mysql
    ports:
      - "3306:3306"
  your_app:
    build:
      context: ./your_folder_dockerfile
      dockerfile: Dockerfile_app
    ...

  angular_serv:
    image: angular-cli-docker-ootb:latest
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM