DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • A Guide to Container Runtimes
  • Docker vs Kubernetes: Which to Use and When?
  • Docker Bake: A Modern Approach to Container Building
  • Containerization of a Node.js Service

Trending

  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice
  • Grafana Loki Fundamentals and Architecture
  • Ensuring Configuration Consistency Across Global Data Centers
  • Unlocking AI Coding Assistants Part 1: Real-World Use Cases
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. How to Run a Docker Container on Your Local Machine

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.

By 
Suleyman Yildirim user avatar
Suleyman Yildirim
·
Sep. 04, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
179.9K Views

Join the DZone community and get the full member experience.

Join For Free

I have been working on a hobby project, a nutrition tracking app, to practice the latest continuous integration tools. This post is about dockerizing an angular2 app 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

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

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

Build 

docker build -t angular-webpack .

 

Run 

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


Test: http://192.168.99.100:9000/index.html

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

Docker (software) Container

Opinions expressed by DZone contributors are their own.

Related

  • A Guide to Container Runtimes
  • Docker vs Kubernetes: Which to Use and When?
  • Docker Bake: A Modern Approach to Container Building
  • Containerization of a Node.js Service

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!