Skip to content

Latest commit

 

History

History
99 lines (66 loc) · 3.32 KB

deployment.md

File metadata and controls

99 lines (66 loc) · 3.32 KB

Docker Deployment

Docker

To run project you only need host machine with operating system with installed git (to clone this repo) and docker and thats all - any other software is not needed (other software like node.js etc. will be automatically downloaded and installed inside docker container during build step based on dockerfile).

Install docker

MacOS:

brew cask install docker

And run docker by Mac bottom menu> launchpad > docker (on first run docker will ask you about password)

Ubuntu:

sudo apt-get update
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-add-repository 'deb https://apt.dockerproject.org/repo ubuntu-xenial main'
sudo apt-get update
apt-cache policy docker-engine
sudo apt-get install -y docker-engine
sudo systemctl status docker  # test:  shoud be �active�

And add your user to docker group (to avoid sudo before using docker command in future):

sudo usermod -aG docker $(whoami)

and logout and login again.

Build image

Because node.js is big memory consumer you need 1-2GB RAM or virtual memory to build docker image (it was successfully tested on machine with 512MB RAM + 2GB virtual memory - building process take 7min)

Go to main project folder. To build big (~280MB) image which has cached data and is able to FAST rebuild
(this is good for testing or staging environment) type:

docker build -t angular-starter .

To build SMALL (~20MB) image without cache (so each rebuild will take the same amount of time as first build) (this is good for production environment) type:

docker build --squash="true" -t angular-starter .

The angular-starter name used in above commands is only example image name. To remove intermediate images created by docker on build process, type:

docker rmi -f $(docker images -f "dangling=true" -q)

Run image

To run created docker image on localhost:8080 type (parameter -p 8080:80 is host:container port mapping)

docker run --name angular-starter -p 8080:80 angular-starter &

And that's all, you can open browser and go to localhost:8080.

Run image on sub-domain

If you want to run image as virtual-host on sub-domain you must setup proxy . You should install proxy and set sub-domain in this way:

docker pull jwilder/nginx-proxy:alpine
docker run -d -p 80:80 --name nginx-proxy -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy:alpine

And in your /etc/hosts file (linux) add line: 127.0.0.1 angular-starter.your-domain.com or in yor hosting add folowing DNS record (wildchar * is handy because when you add new sub-domain in future, you don't need to touch/add any DNS record)

Type: CNAME
Hostname: *.your-domain.com
Direct to: your-domain.com
TTL(sec): 43200

And now you are ready to run image on subdomain by:

docker run -e VIRTUAL_HOST=angular-starter.your-domain.com --name angular-starter angular-starter &

Login into docker container

docker exec -t -i angular-starter /bin/bash