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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Run the official Nginx image with docker run -d --name my-nginx -p 8080:80 nginx, then open http://localhost:8080. The -p 8080:80 option publishes host port 8080 to Nginx’s port 80 inside the container. For anything beyond a quick test, pin an image tag, mount configuration files read-only, and use Docker Compose when Nginx must work with other services.

What the Docker command does

A container packages the Nginx process and its filesystem separately from your host. Nginx still listens on port 80 inside the container, but that port is not reachable from your host unless you publish it with Docker’s -p option.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Command part Meaning
docker run Creates and starts a new container from an image.
-d Runs the container in detached mode so the terminal is returned to you.
--name my-nginx Assigns a predictable name for later commands such as docker logs my-nginx.
-p 8080:80 Maps host port 8080 to container port 80. The left side is the host; the right side is the container.
nginx The image name. Without a tag, Docker uses the image’s default tag, normally latest.

Because the container’s port is 80, changing the host side lets you run Nginx on another free port without changing Nginx’s internal configuration. For example, -p 9000:80 makes the site available at http://localhost:9000.

Prerequisites

  • Install Docker Desktop on Windows or macOS, or Docker Engine with the Compose plugin on Linux.
  • Confirm that Docker is running with docker version.
  • Choose a host port that is not already occupied by another web server or application.
  • If you will mount files, work from a directory containing the configuration or site files you intend to use.

On Linux, commands that access the Docker daemon may require sudo, depending on how your user account is configured. On Docker Desktop, the daemon runs inside Docker Desktop rather than as a native host service.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Start the official Nginx image

Run a disposable default server

  1. Open a terminal.
  2. Run docker run -d --name my-nginx -p 8080:80 nginx.
  3. Check that Docker reports a container ID.
  4. Visit http://localhost:8080. You should see the default Nginx welcome page.

This command downloads the image if it is not already present locally. The container continues running in the background until you stop or remove it.

Verify the container and response

docker ps
docker logs my-nginx
curl http://localhost:8080

docker ps should show my-nginx with a port mapping similar to 0.0.0.0:8080->80/tcp. The curl command prints the HTML returned by Nginx; in a browser, the same request displays the welcome page.

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

Stop, start and remove it

docker stop my-nginx
docker start my-nginx
docker rm my-nginx

docker rm only works after the container has stopped. To remove a running test container in one operation, use docker rm -f my-nginx. Removing a container does not remove the downloaded image.

Choose a reproducible image tag

An untagged image reference such as nginx generally follows the latest tag. That is convenient for a first test, but a future pull can change the Nginx version and alter behavior. Pin a tag for repeatable deployments, for example:

docker run -d --name my-nginx -p 8080:80 nginx:1.25

nginx:1.25 is an example of a pinned major-minor tag from the available guidance, not a guarantee that it is the newest release in 2026. Check the current tags on the official Docker image page before choosing a production tag, and update it deliberately rather than allowing an implicit latest-version change.

Image tags are independent of the host port. You can use any available tag with -p HOST_PORT:80. If you need the same image on multiple machines, record the exact tag in your deployment files and test upgrades before rolling them out.

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

Publish ports safely

Bind to all host interfaces

-p 8080:80 publishes port 8080 on the host’s available interfaces. This is suitable for local testing, but a machine reachable from a network may expose the site beyond the host itself.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Bind only to localhost

For a service that should be reachable only from the same computer, bind the host side explicitly:

docker run -d --name my-nginx -p 127.0.0.1:8080:80 nginx

Now requests must originate on that host. This does not replace application authentication or a firewall, but it prevents ordinary remote connections to that published port.

Diagnose a port conflict

If Docker reports that the address is already in use, select another host port, such as -p 8081:80, or stop the process currently using 8080. The Nginx side remains 80; only the host-side number changes.

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 your Nginx configuration

Containers are replaceable, so keep configuration on the host or in a version-controlled project. Mount configuration read-only with :ro so Nginx cannot write back to the host file.

Replace the main nginx.conf

To supply a complete main configuration, mount your file over /etc/nginx/nginx.conf:

docker run -d 
  --name my-nginx 
  -p 8080:80 
  -v "$(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro" 
  nginx:1.25

The left side of the volume mapping is the host file. The right side is the path Nginx reads inside the container. Because this replaces the main file, your version must include all directives required by the image’s normal configuration, including an appropriate events block and an http block. A file containing only a server block is not a complete replacement.

Add a server file under conf.d

If you want to retain the image’s main configuration and add or replace a virtual host, mount one file at /etc/nginx/conf.d/default.conf:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
docker run -d 
  --name my-nginx 
  -p 8080:80 
  -v "$(pwd)/default.conf:/etc/nginx/conf.d/default.conf:ro" 
  nginx:1.25

This approach leaves /etc/nginx/nginx.conf in place and changes the included server configuration. It is usually the safer choice when you only need a custom listener, document root or reverse-proxy rule.

Example server configuration

server {
    listen 80;
    server_name _;

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }
}

Save that text as default.conf in the directory from which you run Docker. The underscore catch-all name lets the server respond when the request’s host name does not match a more specific name. If you mount a different document root, that directory must also exist inside the container; a host path is not automatically visible just because the configuration mentions it.

Validate and reload configuration changes

Test before reloading

Run Nginx’s configuration test inside the container:

docker exec my-nginx nginx -t

A successful test reports that the syntax is okay. If the command identifies a file and line number, correct that file on the host and run the test again. Never reload a configuration that fails this check.

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

Reload without replacing the container

Editing a bind-mounted file changes what the container sees, but the running Nginx master process does not automatically reread it. After a successful test, request a reload:

docker exec my-nginx nginx -s reload

Existing worker processes finish current requests while new workers use the updated configuration. If a reload is not appropriate for your change, restart the container instead:

docker restart my-nginx

A restart is disruptive for active connections and should be treated differently from a graceful reload.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Read logs when a request fails

docker logs my-nginx
docker logs --tail 100 -f my-nginx

The first command prints the container’s accumulated standard output and error. The second follows the most recent 100 lines. Also inspect the HTTP status with curl -I http://localhost:8080 to distinguish a connection problem from an Nginx response such as 404 or 502.

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

Use Docker Compose for repeatable setups

Compose stores the image, port mapping, mounts and restart behavior in one YAML file. It is the natural next step when Nginx must run alongside an application container.

Minimal Compose file

services:
  nginx:
    image: nginx:1.25
    container_name: my-nginx
    ports:
      - "8080:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro

Save this as compose.yaml beside nginx.conf. The ports entry has the same host-to-container meaning as -p, and the volumes entry has the same host-path-to-container-path meaning as -v.

Start and manage the project

docker compose up -d
docker compose ps
docker compose logs -f nginx
docker compose exec nginx nginx -t
docker compose down

docker compose up -d creates or recreates the service in the background. Run it again after changing the Compose file. docker compose down stops and removes the project’s containers and network; it does not remove the image or your bind-mounted files.

Mount a conf.d file instead

services:
  nginx:
    image: nginx:1.25
    ports:
      - "8080:80"
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro

Use the main-file mount when you intentionally own the entire Nginx configuration. Use the conf.d mount when the image’s main file should remain intact and your project needs to supply a server definition.

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.

Reverse-proxy another container

In a Compose project, services share a project network by default. Nginx can address another service by its Compose service name rather than by localhost. Inside the Nginx container, localhost means Nginx itself, not the host and not the application container.

Compose example

services:
  nginx:
    image: nginx:1.25
    ports:
      - "8080:80"
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app

  app:
    image: your-application-image

The corresponding default.conf can proxy to the service name:

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
server {
    listen 80;

    location / {
        proxy_pass http://app:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Replace 3000 with the port on which the application listens inside its container. Do not use the host-published port for container-to-container traffic unless you have a specific reason; the service name and internal port are the direct path on the Compose network.

depends_on controls startup order but does not prove that the application is ready to accept requests. If Nginx starts before the application is ready, inspect logs and use an application health check or retry strategy appropriate to that application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Serve local static files

To serve files from the host, mount a directory into the container and point the server’s root there:

docker run -d 
  --name my-nginx 
  -p 8080:80 
  -v "$(pwd)/public:/usr/share/nginx/html:ro" 
  nginx:1.25

Place index.html in the host’s public directory, then open http://localhost:8080. The read-only flag protects the host files from writes by the container. If you also mount a custom default.conf, make sure its root points to the same in-container path.

Troubleshooting by symptom

“Connection refused” or the browser cannot connect

  • Run docker ps and confirm the container is running.
  • Check the published mapping with docker port my-nginx.
  • Use the exact host port from the left side of -p, such as 8080.
  • Read docker logs my-nginx for an immediate startup failure.
  • If another process owns the host port, choose a different one.

The container exits immediately

Inspect docker ps -a and then docker logs my-nginx. A malformed replacement nginx.conf, a missing required top-level block or an invalid directive can prevent Nginx from starting. Run an isolated syntax test after correcting the mounted file.

Configuration changes have no effect

  • Confirm that the host file is mounted at the path Nginx actually includes.
  • Run docker exec my-nginx nginx -t.
  • Reload with docker exec my-nginx nginx -s reload, or restart the container.
  • Check that your request reaches the expected server block and host port.

Requests return 404

Verify the configured root, the filename under that directory and the mounted directory contents. A host path in a configuration file is not available inside the container unless it has been mounted to the same in-container location.

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

Requests return 502 from a reverse proxy

Check that the upstream service name matches the Compose service key, that the internal port is correct and that the application is running. From the Nginx container, DNS and network problems are different from an application that is listening too late; use Compose status and both services’ logs to separate those cases.

Bind mounts fail on Windows

A Docker for Windows GitHub issue titled “Cannot mount nginx config to volume in nginx container using docker-compose or docker” documents mount failures, but the search result does not establish a universal cause or a verified fix. Check Docker Desktop’s file-sharing permissions, use an absolute path in the volume mapping and confirm that the file exists before treating the issue as an Nginx configuration error.

Operational checklist

  • Pin an explicit image tag instead of relying on an unqualified image name.
  • Publish only the host ports that users need, and bind local-only services to 127.0.0.1.
  • Keep configuration in your project and mount it with :ro.
  • Choose a full nginx.conf replacement or a conf.d server mount deliberately.
  • Run nginx -t before every reload.
  • Use Compose when Nginx and an application must share a network.
  • Use service names for proxy upstreams, not localhost from inside the Nginx container.
  • Review logs and the actual port mapping before changing application code.

Which setup should you use?

Need Recommended approach Reason
Try the default page docker run -d --name my-nginx -p 8080:80 nginx Fastest path with no local files.
Own the entire Nginx configuration Mount nginx.conf to /etc/nginx/nginx.conf:ro Every top-level directive comes from your project.
Add one virtual host while keeping image defaults Mount a file to /etc/nginx/conf.d/default.conf:ro Changes only the included server configuration.
Run Nginx beside an application Use Compose and proxy to the application service name Services share a managed network and configuration is repeatable.
Serve host-built static files Bind-mount the content directory read-only Edits on the host become available without rebuilding the image.

The smallest working setup is the one-line docker run command. Once configuration, a second service or repeatable deployments enter the picture, Compose and explicit mounts make the relationships visible and easier to operate.

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.

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