R
R
Roman2016-11-28 23:43:15
Angular
Roman, 2016-11-28 23:43:15

What is the best way to develop a project with docker?

I'm just getting started with the angular, node, mongo and Docker stack, there is a project that runs with different separate containers from nginx, redis, mongo and npm images the application itself is in angular, koa with webpack.
All this is put into a small bash script with different commands

#!/bin/bash

SERVICE_NAME="web_app"

if ; then
  docker-compose up -d [email protected]
elif [ $1 = 'restart' ]; then
  docker-compose down && docker-compose up -d [email protected]
elif [ $1 = 'dev' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm run dev ${@:2}
elif [ $1 = 'test' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm run test ${@:2}
elif [ $1 = 'debug' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm run dev:debug ${@:2}
elif [ $1 = 'exec' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME ${@:2}
elif [ $1 = 'i' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm i --save ${@:2}
elif [ $1 = 'idev' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm i --save-dev ${@:2}
elif [ $1 = 'un' ]; then
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run --rm --service-ports $SERVICE_NAME npm un -save ${@:2}
elif [ $1 = 'build' ]; then
  docker-compose build "${@:2}" --no-cache
elif [ $1 = 'rebuild' ]; then
  docker-compose build --no-cache
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run $SERVICE_NAME npm i
  docker-compose -f docker-compose.yml -f docker-compose.dev.yml run $SERVICE_NAME npm run build
else
  docker-compose up -d [email protected]
fi

It all works and runs great, both locally under Windows 10 and on an Ubuntu 16.04 server. I come from the world of PHP, and I'm used to the fact that when making changes, I refresh the browser and immediately see the changes or debugging through the IDE debugger.
But here I just can’t understand how I can set up updating the project code when developing in an application container.
Let's say I changed CSS, JS, wrote something in the controller or model or template, I want to refresh the page in the browser and immediately see the changes in the running docker container where the application is placed, and if I need to add a module via npm, this is every time I go the exec command to the container and run the command inside, and after the docker-compose down or stop commands, will all changes be saved?
So for every change, do I have to run docker-compose down && docker-compose up -d to see the changes in the container and in the browser? It is not entirely clear how to work with the database in the docker container, if you need to roll up changes in the structure or access the database through PhpMyAdmin.
Advise how to automate this and better understand the principles of work. And there are still issues of backup, database replication in Docker ahead.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-11-29
@healqq

Project files on dev must be mounted from your host OS. Then everything will be updated on the fly. Concerning restart of the server - it is possible to take the same nodemon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question