简体   繁体   中英

How to properly dockerize a mean stack application?

I'm developing a mean stack application (running angular 6, not 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

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

simple 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 container for app
  • 1 container for database.

Furthermore defining one Dockerfile for each one, you can define a docker-compose.yml which can build and deploy all of them.

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.

Manage and define some ARGS / ENV for DB parameters.

docker-compose.yml example:

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
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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