I have been working on a hobby project, Nutrition Tracking App, to practice the latest Continuous Integration tools. This post is about dockerizing an Angular2 app and on your local machine. I skipped the basic definitions about Docker, containers, and CI for the sake of simplicity.
Frequently used Docker commands:
Build Docker Image
docker build -t image-name .
Run Docker Image
docker run -p 80:80 -it image-name
Stop All Docker Containers
docker stop $(docker ps -a -q)
Remove All Docker Containers
docker rm $(docker ps -a -q)
Remove All Docker Images
docker rmi $(docker images -q)
Port Bindings of a Specific Container
docker inspect [container-id]
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Here's a simple Dockerfile that copies the "dist" folder to /usr/share/nginx/html:
FROM nginx COPY dist /usr/share/nginx/html EXPOSE 80
The Dockerfile should be located in the root of the project. Here is an example from my project:
How to Run the Docker Container on Your Local Machine
docker build -t angular-webpack .
docker run -p 9000:80 -t angular-webpack
This will create a container with the image "angular-webpack" and bind the container’s port 80 to the host machine’s port 9000. After the "docker run -p 9000:80 -it angular-webpack" command, the Docker container runs on a Linux virtual machine. So we can't run Docker natively on Windows or a Mac. The following properties must be set:
Set Environment Properties
set USERPROFILE = C:\Users\xxx --> set your user proile set DOCKER_CERT_PATH=%USERPROFILE%\.docker\machine\machines\default set DOCKER_HOST=tcp://192.168.99.100 --> find this IP in Docker Quick Start terminal set DOCKER_MACHINE_NAME=default set DOCKER_TLS_VERIFY=1