Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk9 min

How to Run Nginx in a Docker Container on Ubuntu

Start NGINX on Ubuntu with Docker, publish the right port, mount your website and configuration safely, preserve data with volumes, and diagnose network and startup failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The shortest working setup is Docker’s official NGINX image and one port mapping: docker run --name mynginx -p 8080:80 -d nginx. Docker starts NGINX inside a container, publishes the container’s port 80 on Ubuntu port 8080, and lets you browse to http://<ubuntu-host>:8080. You do not need a separate NGINX installation on the Ubuntu host.

This guide covers Docker installation, image tags, port exposure, custom HTML, nginx.conf mounts, persistence, lifecycle commands, firewall implications, and the failure modes that most often make a container appear unreachable.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What runs where

Docker Engine runs the container and supervises its main process. The official NGINX image already contains the NGINX binaries and a default configuration, so Ubuntu only needs a working Docker installation. The container has its own filesystem and network namespace; files and ports become visible to the host only when you explicitly publish or mount them.

In -p 8080:80, 8080 is the port on the Ubuntu host and 80 is the port inside the container. NGINX listens on container port 80 by default. Changing the first number changes the URL you use; changing the second number would require NGINX to listen on a different internal port.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Install Docker Engine on Ubuntu

Configure Docker’s official Ubuntu apt repository before installing the Engine packages. The documented package set is:

Package Purpose
docker-ce Docker Engine daemon
docker-ce-cli Docker command-line client
containerd.io Container runtime used by Docker
docker-buildx-plugin BuildKit-based image building
docker-compose-plugin Compose commands integrated into the Docker CLI

After the repository is configured, install the set with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Check that the daemon is running. If it is inactive, start it before trying to launch NGINX:

sudo systemctl status docker
sudo systemctl start docker

Verify the installation independently of NGINX:

sudo docker run hello-world

A successful hello-world run confirms that the client can contact the daemon and that Docker can create a container. If the command reports that it cannot connect to the Docker daemon, resolve the service state first; an NGINX command cannot work until Docker Engine is running.

Choose an NGINX image tag

The image name nginx selects the Docker Official Image. Tags available in the documented image listing include 1.31.6, mainline, 1, 1.31, and latest. Tags can change as new releases are published, so choose deliberately:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Tag style What it gives you When to use it
1.31.6 A specific release Reproducible deployments and controlled upgrades
1.31 or 1 A moving minor- or major-line tag Receiving compatible updates while limiting the release family
mainline The moving mainline stream Testing newer NGINX changes before adopting a fixed release
latest A mutable default tag Simple experiments where automatic image changes are acceptable

Use a pinned release in production or anywhere you need the same image after a container is recreated. Use latest only when you have an update and rollback process.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start the first NGINX container

Run this command from any directory:

sudo docker run --name mynginx -p 8080:80 -d nginx

Docker downloads the image if it is not already local, creates a container named mynginx, publishes host port 8080 to container port 80, and detaches after starting NGINX. To use a deliberate image tag, replace the final word, for example:

sudo docker run --name mynginx -p 8080:80 -d nginx:1.31.6

Open http://<ubuntu-host>:8080 from a browser that can reach the Ubuntu machine. On the Ubuntu machine itself, http://localhost:8080 tests the local path. If you prefer the conventional HTTP port, publish it with:

sudo docker run --name mynginx -p 80:80 -d nginx

Only one process can occupy a host port at a time. If another service already uses port 80 or 8080, choose a free host port or stop the conflicting service.

Check, stop, restart, and remove the container

Use these commands to inspect the basic lifecycle:

Task Command Result
List running containers sudo docker ps Shows mynginx, its image, status, and published ports
View NGINX output sudo docker logs mynginx Displays startup and request-related messages sent to the container log
Stop NGINX sudo docker stop mynginx Stops the container without deleting it
Start an existing container sudo docker start mynginx Starts the stopped container with its original settings
Remove a stopped container sudo docker rm mynginx Deletes the container; mounted data remains where it was stored

If docker ps is empty, include stopped containers with sudo docker ps -a. A container that exited immediately usually has a configuration or startup error; inspect its logs before removing it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Publish the port safely

An unqualified mapping such as -p 80:80 publishes on all host interfaces by default. That makes NGINX reachable through every address assigned to Ubuntu, subject to routing and other network controls. For a service that should be reachable only from the Ubuntu machine, bind the host side to loopback:

sudo docker run --name mynginx-local -p 127.0.0.1:8080:80 -d nginx
Mapping Exposure Typical use
-p 8080:80 All host interfaces, host port 8080 A LAN or Internet-facing service after exposure has been reviewed
-p 80:80 All host interfaces, host port 80 Serving ordinary HTTP on the standard port
-p 127.0.0.1:8080:80 Loopback only Local development, a reverse proxy on the same host, or an SSH-tunneled service

Ubuntu firewall behavior needs special attention. Docker’s installation guidance warns: “If you use ufw or firewalld to manage firewall settings, be aware that when you expose container ports using Docker, these ports bypass your firewall rules.” Treat a published port as exposed until you have verified the Docker-supported iptables path and your host’s network policy. Do not assume that an uncomplicated firewall rule alone limits a port published by Docker.

Serve your own HTML with a bind mount

The default image serves files from /usr/share/nginx/html. A bind mount maps a directory on Ubuntu into that document root, so edits on the host appear in the container without rebuilding the image.

  1. Create a site directory and a test page:
mkdir -p "$PWD/html"
printf '%sn' '<h1>Hello from Ubuntu and Docker</h1>' > "$PWD/html/index.html"
  1. Run NGINX with the directory mounted read-only:
sudo docker run --name mynginx-content -p 8080:80 -v "$PWD/html:/usr/share/nginx/html:ro" -d nginx
  1. Browse to http://<ubuntu-host>:8080. The page should contain the text from your host’s index.html.

The :ro suffix prevents the container from writing into the host directory. Use an absolute host path when launching from scripts or service managers, and confirm that the directory contains the files you intend to publish. If the default NGINX page still appears, check that the mount source is the directory you edited and that the container was recreated with the mount; changing a mount requires removing and running a new container.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Mount a custom nginx.conf

For server blocks, proxy settings, custom headers, or non-default document roots, mount a tested configuration file at the image’s NGINX configuration path:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
sudo docker run --name mynginx-config -p 8080:80 
  -v "$PWD/html:/usr/share/nginx/html:ro" 
  -v "$PWD/nginx.conf:/etc/nginx/nginx.conf:ro" 
  -d nginx

Adapt the host paths and confirm the destination path for the specific image tag you selected. A read-only configuration mount is safer for change control, but NGINX may need to write to other locations depending on your configuration. The official image documentation notes that read-only mode requires mounting every location where NGINX writes; review cache, temporary, PID, and log paths before enforcing read-only behavior.

Validate the file before replacing a working container. A syntax error can make NGINX exit during startup, leaving no listening service. Keep a known-good copy of the last configuration and use sudo docker logs mynginx-config immediately after a failed start to identify the file and line reported by NGINX.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep data when containers are replaced

Containers are disposable. A bind mount keeps files in a chosen Ubuntu directory; a named volume lets Docker manage the storage location and lifecycle.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Storage method Best for Trade-off
Bind mount, such as $PWD/html:/usr/share/nginx/html:ro Website source, configuration under version control, and files edited directly on the host You manage host paths, permissions, backups, and directory layout
Named volume Data that must survive container removal without depending on a particular host path Files are less visible in the project directory and should be inspected or backed up through Docker-aware workflows

Create and use a named volume like this:

sudo docker volume create nginx-data
sudo docker run --name mynginx-volume -p 8080:80 -v nginx-data:/usr/share/nginx/html -d nginx

List volumes with sudo docker volume ls. Remove a volume only when its contents are no longer needed:

sudo docker volume rm nginx-data

Removing a container does not remove a separately managed named volume, while removing the volume permanently deletes the data stored in it.

Keep NGINX in the foreground

Docker supervises the process running as PID 1 in the container. NGINX must stay in the foreground rather than daemonizing and exiting. The container pattern is:

CMD ["nginx", "-g", "daemon off;"]

This is the command pattern documented for NGINX containers at NGINX’s Docker installation documentation. The standard image already applies the required foreground behavior, so you normally do not need to add it to docker run. If you build a custom image, preserve the foreground command or Docker will see the main process exit and stop the container.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between one command, Compose, and a custom image

Approach Configuration method Operational profile
Single docker run Flags for ports and mounts Fastest for a test site or one container; settings remain in shell history or notes
Compose A YAML file describing image, ports, and volumes Repeatable multi-container deployments and easier start/stop operations using the Compose plugin
Custom image A Dockerfile copies site files and configuration into an image Versioned, portable artifacts; rebuilding is required whenever baked-in content changes

Use a bind mount when you expect to edit files on Ubuntu frequently. Use a custom image when the exact content and configuration should travel together through a build pipeline. Use Compose when NGINX is one part of a larger application or when you want the complete deployment definition in one file.

Troubleshoot an unreachable NGINX container

The Docker command cannot connect to the daemon

Run sudo systemctl status docker. If the service is inactive, start it with sudo systemctl start docker, then repeat sudo docker run hello-world. This separates an Engine problem from an NGINX problem.

The container is not running

Run sudo docker ps -a and sudo docker logs mynginx. A stopped container commonly indicates an invalid mounted configuration, a missing file, or a foreground-process mistake in a custom image. Correct the cause and create a new container with the corrected options.

The browser says connection refused

  • Confirm the container is listed as running with sudo docker ps.
  • Confirm the published port in the output matches the URL, such as 0.0.0.0:8080->80/tcp for -p 8080:80.
  • Test locally with curl http://127.0.0.1:8080 on Ubuntu to distinguish an NGINX failure from an external routing problem.
  • Check that no other process prevented Docker from binding the selected host port.
  • If remote clients fail but local access works, review the host address, upstream network rules, cloud security controls, and Docker’s firewall interaction.

The wrong page appears

Inspect the bind source and destination. The usual document root is /usr/share/nginx/html; mounting a different path does not change what NGINX serves. Confirm that index.html exists in the host directory and recreate the container if the original container was started without the mount.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changes to nginx.conf have no effect

Ensure the file is mounted to /etc/nginx/nginx.conf for the selected image and that the container was created with the updated file. A configuration edit on the host does not automatically recreate a container or reload NGINX. Check the container logs after restarting, and retain the previous working file so you can recover from a syntax error.

Remote access works despite a UFW rule

That behavior is consistent with Docker’s warning that published ports can bypass UFW or firewalld rules. Reconsider whether the service should be published on all interfaces; use a loopback binding for host-only access and apply Docker-supported packet-filtering controls for public exposure.

Operational checklist

  • Docker Engine and its daemon are installed from the official Ubuntu repository and pass the hello-world test.
  • The image tag is intentional rather than accidentally mutable.
  • The host-to-container mapping is correct, and the host port is free.
  • The binding scope is appropriate: all interfaces only when remote access is required, loopback otherwise.
  • Custom HTML and configuration are mounted from the intended host paths.
  • Configuration mounts are tested before deployment, with a rollback copy available.
  • Important data is stored in a bind mount or named volume rather than only in the container’s writable layer.
  • Logs are checked after startup and after every configuration change.
  • Firewall and network exposure have been reviewed because Docker-published ports may bypass ordinary UFW or firewalld expectations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.