Sunday, 11 October 2026

Start up nginx Docker container and edit homepage

This article will be a quick tip how to get a web server up and running on your system, in this case using Docker image nginx to spin up a container. First off, install Docker. To install docker:
  • The Docker website contains the container software you need to quickly spin up nginx. You need an account there, you can use for example a Google account to log in and create the account
  • You probably want to use for just experimentation the Personal plan, which is free. Go to https://docs.docker.com/get-started/get-docker/
  • Install Docker for Desktop for your OS - Linux, Windows or Mac
To get nginx up and running, do the following commands from the command line, after Docker is installed and Docker for Desktop has been started. This will make sure the Docker background system processes are running (Docker deaemon).

docker command (CLI)
        │
        ▼
Docker daemon (dockerd)
        │
        ├─ Creates containers
        ├─ Pulls images
        ├─ Creates networks
        ├─ Manages volumes
        └─ Starts/stops containers
        
 

Links to Nginx and Docker hub Nginx image



https://nginx.org

The docker hub image for nginx is here, it has been downloaded a billion times plus.

https://hub.docker.com/_/nginx

Getting nginx running on your system

First off we start the nginx image (it will be pulled the first time and downloaded, then cached later on). It is run as a daemon background service with -d. nginx will run at port 8080 to avoid conflicting with other services running at port 80 such as IIS web server. The nginx project's homepage is here:


docker run -d --name nginx_test -p 8080:80 nginx

Here, we name the container as nginx_test The system prompts back the container id We can also see the containers running image with name nginx like this :

docker ps --filter ancestor=nginx


CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                     NAMES
a2cc9ed9b212   nginx     "/docker-entrypoint.…"   12 minutes ago   Up 12 minutes   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp   nginx_test
ea3bf3541852   nginx     "/docker-entrypoint.…"   12 hours ago     Up 12 hours     80/tcp                                    container-b
505eec83cca5   nginx     "/docker-entrypoint.…"   12 hours ago     Up 12 hours     80/tcp   

In this case, I tested some nginx containers some hours ago and they are still running. We can stop containers by running docker stop <container-id> Our nginx_test container is now running, we can enter the container next.

docker exec -it nginx_test bash

The Linux OS that is running inside the nginx container has no editor installed, not even vim og vi (it is optimalized to use minimal disk space so it got the bare minimum to run the web server nginx itself). Lets install nano to edit files inside the container!

apt-get update
apt-get install nano

The homepage of nginx is installed in /usr/share/nginx/html Edit the index.html file by running nano . nano index.html

cd /usr/share/nginx/html
nano index.html

You can save the index.html file after editing in nano by entering Ctrl+O and write to the file.




Additional notes

This is just for testing out nginx. To stop all containers on your system for example, you can either exit out of Docker for desktop or run this command (Powershell, other OS-es got similar command):


docker stop $(docker ps -q)


This will output the container ids of what was stopped. Afterwards, you can check that no containers are running using this:


docker ps


You should see an empty list of containers, i.e. no containers running on your system.
 ~#@❯ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Just to note, if you are to run nginx on a server you most definately want to enable a drive for your container, for durability. But for now, this article was just a short article how to get a web server such as nginx up and running on your system and play around with Docker. Windows Users - Please note Docker takes much resources, so to stop Docker in Windows and if you run the default setup of using WSL2 containers, this command should stop Docker. You can start up Docker again by just running Docker Desktop again.

wsl --shutdown
taskkill /F /IM "Docker Desktop.exe"


Share this article on LinkedIn.

No comments:

Post a Comment