<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Onno de Jong on Medium]]></title>
        <description><![CDATA[Stories by Onno de Jong on Medium]]></description>
        <link>https://medium.com/@o.dejong?source=rss-b55be8ca7de0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*-cXvdNpsfRhpvxwT.jpg</url>
            <title>Stories by Onno de Jong on Medium</title>
            <link>https://medium.com/@o.dejong?source=rss-b55be8ca7de0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:50:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@o.dejong/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to set up an Angular CLI project with Docker Compose]]></title>
            <link>https://medium.com/joolsoftware/how-to-set-up-an-angular-cli-project-with-docker-compose-a3ec78f179ab?source=rss-b55be8ca7de0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3ec78f179ab</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[angular-cli]]></category>
            <dc:creator><![CDATA[Onno de Jong]]></dc:creator>
            <pubDate>Mon, 15 Apr 2019 11:39:35 GMT</pubDate>
            <atom:updated>2019-04-15T11:43:57.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cx5qHdUMRGiQeyNdnnBSZw.png" /><figcaption><strong>Design by:</strong> Vivian Bierhuizen</figcaption></figure><h3>Introduction</h3><p>In this post I would like to give a quick introduction about how to get your Angular project running in Docker. When developing our application locally, the expectation is that the container will reload our new application just like you are used to when developing locally.</p><p>This solution will work on existing angular projects as well as on new projects.</p><p>We will start of with creating a Dockerfile and use the Docker Compose tool to run our service.</p><h4>What are we going to do</h4><p>This post will guide you all the way from creating an Angular project with the CLI to a Docker setup, including reload on file changes.</p><p>In order to do so, we need the following prerequisites as displayed bellow.</p><ul><li>Node 8+</li><li>Angular CLI</li><li>Docker V18+</li><li>Preferably a Linux OS, but Mac will do as well. I won’t encourage Windows.</li></ul><h4>Installing Node on your machine</h4><p>This post won’t cover how to install Node, but here is a link to the official download page.</p><p><a href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a></p><h4>Installing the Angular CLI</h4><p>The first step is to install the Angular CLI on your local machine. The Angular CLI is the command line interface that provides multiple useful tools including creating new projects, components and services.</p><pre>npm install -g @angular/cli </pre><h4>Create a new project</h4><p>Create a new project.</p><pre>ng new angulardockerproject</pre><p>navigate to the project folder.</p><pre>cd angulardockerproject</pre><h4>The Dockerfile</h4><p>To run a Docker container we need an image. This image is defined in a Docker file.</p><p>In the Docker file we can use the following instructions:</p><p>FROM,WORKDIR ,COPY, RUN, ENV, EXPOSE, CMD</p><p>Docker then, will read these instructions to build a Docker container, but we’ll get to that later.</p><p>Lets create one in the project folder.</p><pre><em>touch Dockerfile</em></pre><p>Within this Dockerfile, we will define the Docker image. In order to do this we need to add a starting point, which is another image. To define a starting point we use the <em>FROM</em> instruction, followed by the image we would like to use.</p><blockquote>To use an empty image we could use “FROM scratch”, but we will use the Node:8 image because that is exactly what we need for our Angular environment.</blockquote><pre># This defines our starting point<br>FROM node:8 </pre><p>Amazing, we’ve defined our starting point. Let’s define an instruction to create a working directory for our app. First we need to create a directory with the <em>RUN</em> instruction, after that we will make that our working directory using the <em>WORKDIR</em> instruction.</p><pre>RUN mkdir /usr/src/app <br> <br>WORKDIR /usr/src/app</pre><p>Now we have defined our directory, we are ready to install the Angular CLI, lets do that right away. The node image provides us with NPM, which means we can install NPM packages with the RUN command.</p><pre>RUN npm install -g @angular/cli </pre><p>The next thing we need to do is to copy our Angular application to our Docker instance. We can do that using the COPY instruction. The copy instruction uses two paths as parameters similar to the CP command.</p><pre>COPY . . </pre><p>That’s it, that is the Dockerfile for now. It is the bare minimum but it should be enough for our example.</p><p>Lets test our Dockerfile by building it.</p><pre>docker build -t testimage .</pre><p>To see our image(s) we can use the following command.</p><pre>docker images</pre><p>For now, we will remove our image again. Because we are going to build our image with Docker compose. Removing the image is simple, check your IMAGE ID that you can see in the Docker image output.</p><blockquote>Image id’s look like this: d304814c7120</blockquote><pre>docker image rm &lt;your image id&gt;</pre><h4>The docker-compose file</h4><p>A Docker file is enough to build, but we want to be able to start multiple containers with one file. For example, if we also want to add our Node Express back-end application and our database which all contain their own Dockerfile, we could manage them within a single configuration.</p><p>This is where we can use the docker-compose tool.</p><blockquote>Docker compose is a tool which reads a docker-compose YAML file to start your application services.</blockquote><p>Lets create one outside our Angular project folder.</p><pre>cd ../<br>touch docker-compose.yml</pre><p>A Docker compose file starts of with the version of the configuration file that we are going to use.</p><pre>version: &#39;3.5&#39;</pre><p>Below the version we start defining our services. Our service will be called angular-service.</p><p>Here we also need to define the container name we generate with the CONTAINER_NAME instruction and the build location of our Dockerfile with the BUILD instruction.</p><p>Next we map our volumes from our local directory to the directory that we make in our environment with the VOLUMES instruction.</p><p>Then we specify on which port we want to run our application and what port we have exposed in our Dockerfile with the PORTS instruction.</p><pre>version: &#39;3.5&#39; # We use version 3.5 syntax<br>services: # Here we define our service(s)<br>    angular-service: # The name of the service<br>      container_name: angularcontainer  # Container name<br>      build: ./angulardockerproject # Location of our Dockerfile<br>      volumes: # Volume binding<br>        - &#39;./angulardockerproject:/usr/src/app&#39; <br>      ports: <br>        - &#39;4200:4200&#39; # Port mapping<br>      command: &gt; <br>        bash -c &quot;npm install &amp;&amp; ng serve --host 0.0.0.0 --port 4200&quot;</pre><p>The COMMAND instruction is a way to instruct Docker to run <em>npm install</em> and <em>ng serve</em>. This is one way to do it, I will use this example for now but there are other ways to install the node packages and run the application.</p><blockquote>The following command opens bash in the running container:</blockquote><blockquote>docker exec -i -t container_name /bin/bash</blockquote><blockquote>In this container you could also install the node packages and serve the application.</blockquote><h4>Run docker compose</h4><p>Run the docker-compose.yml file by the following command. We use the build parameter to build the image we defined in our Dockerfile if it not exists already. I like to use the -d parameter to run docker in the background.</p><pre>docker-compose up --build -d</pre><h4>How to monitor what is happening</h4><p>To see which Docker containers are running, we can run.</p><pre>docker ps</pre><p>To see all of the images that are built.</p><pre>docker images</pre><p>To stop a container, we can use.</p><pre>docker container stop angularcontainer</pre><h4>Conclusion</h4><p>In this document we learned how to create a Dockerfile to define our image(s). How to use docker compose to run our container and we learned how to monitor our running containers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3ec78f179ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/joolsoftware/how-to-set-up-an-angular-cli-project-with-docker-compose-a3ec78f179ab">How to set up an Angular CLI project with Docker Compose</a> was originally published in <a href="https://medium.com/joolsoftware">Jool Software Professionals</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>