npm install -g @angular/cli
or if you use Yarn, run yarn global add @angular/cli
.ng new
command to create a new Angular 9 project. Make sure you answer all the questions you get in the terminal because this is going to make the setup very easy.ng new project-name
ng new project-name --packageManager=yarn
project-name
folder and run ng serve
. When everything works as expected, you can open your browser with localhost:4200.docker -version
. If you see a version number, everything is good to go to the next step.Dockerfile
, notice there is no file extension. (That's correct.)node:13.3.0
, if you want to use another version or smaller base image, check the Node.js Docker page. We call that image compile-image
, this will become handy later on.WORKDIR
to /opt/ng
so we know the directory where everything will be copied to with the COPY
line.yarn
command as you would do on your local computer.npm install
command to install all the dependencies.ng build --prod
. It is recommended to run this command on your computer before creating a Docker image, this will save you from constantly building a Docker image that is failing.FROM
statement where we specify we want to use nginx
.COPY
statement copies the default.conf
file from the nginx
base image to the Docker image we are building.COPY
statement tells it that we want some files from the compile-image
. So, underwater, it has built the first part of the image in a separate Docker image./dist
folder in the compile-image
to the html
folder of NGINX.node_modules
folder. We only use the files of our application. This will save some bytes on the Docker image.Dockerimage
file. We are ready to run the command to build our image.docker container ls
.) You don't need the long ID, just type the first three or four characters, that will be enough.docker run
command above.USERNAME
with your username and TOKEN
with the token you have created via the GitHub website. Give the token a name and select the repo, write:packages
, read:packages
, and delete:packages
.IMAGE_ID
with your image ID. Next, replace everything in the URL with your information. For VERSION
, you can start with 0.0.1
or anything else that makes sense for you.For this post I would like to thank Frank Spijkerman who helped me creating this fast Docker image setup. 🙏
I’ve gathered a couple of aspiring developers around the world on a Discord server, feel free if you like to join in.