Over a million developers have joined DZone.

How to Run a Docker Container on Your Local Machine

DZone's Guide to

How to Run a Docker Container on Your Local Machine

This quick walkthrough will show you how to dockerize and run an Angular2 app in a container on your local machine, with frequently used Docker commands.

· DevOps Zone ·
Free Resource

Discover how you can reduce your Kubernetes installation from 22 steps to 1.

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.

Docker Commands

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]


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

Project Structure

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:// --> find this IP in Docker Quick Start terminal




For troubleshooting: https://stackoverflow.com/questions/41208782/docker-localhost-process-not-working-on-windows.

Download the Kubernetes cheatsheet to learn more about how easy it is to run Kubernetes on any infrastructure with Mesosphere DC/OS

docker ,containers ,devops

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}