Running this blog in a container using nginx
2025-02-27 - Peter NylanderIntroduction
In this post, we will look at how to run this blog in a container using NGINX. This is a great way to test the blog locally without having to install a web server on your local machine.
Building the blog
Before we can run the blog in a container, we need to build the blog. Browse to the root of the blog and run the following command.
npm run build
Pulling the image
Let’s start by pulling the NGINX image from Docker Hub by running the following command.
docker pull nginx
Create the container
When the image is downloaded, we will create the container and mount the content of the blog to the container. This way, we can easily update the content without having to rebuild the image.
docker run --name nginx-astro -p 80:80 -v ${pwd}/dist:/usr/share/nginx/html nginx
If you want to start the container in detached mode, you can add the -d
flag to the docker run
command.
docker run --name nginx-astro -p 80:80 -v ${pwd}/dist:/usr/share/nginx/html -d nginx
The container is exposed on port 80, which is the default port for HTTP traffic. The content of the blog is mounted to /usr/share/nginx/html
in the container. This is the default location for the NGINX web server.
Browse to http://localhost
to access the blog.
Note that the blog is not running in development mode, so you will not be able to see changes in real-time. You will have to rebuild the blog and restart the container to see the changes.