My web application consists from 3 docker containers: app (main container with code), redis and node. I have the deployment shell script which do the following things:
- clones master from git (
git clone <...> $REVISION) - removes all files from document root directory (
rm -rf $PROJECT_DIR) - move everything cloned into document root (
mv $REVISION $PROJECT_DIR) - stop all running containers: (
docker-compose stop) - remove all stopped containers (
docker-compose rm -f) - build containers (
docker-compose build) - run all built containers (
docker-compose up -d) - run all init and start scripts inside the containers via
docker exec(for example: config compilers, nginx reload)
And this works fine for me, but I have several doubts in this scheme:
- In step 6, if I don't change files into node container, it will use already built image - it is fast. But if I change something, the container will build again - it is slow and increases unused images
- In the worst case (when I made changes into node code) deployment lasts maybe about 2-3 minutes, in the best case - about 30 seconds. But even then it's a downtime for some users.
As I think, I need the availability to build the new container (in parralel of old container continue working), and only after a successfull status - change the tag of latest container, which is used by the app. How can I do this?
Will be very thankful for your comments.