Running Nginx in Docker

Running Nginx in Docker

Nginx is one of the most popular Docker images. This guide covers common use cases.

Quick Start

docker run -d -p 80:80 --name webserver nginx

Visit http://YOUR_SERVER_IP to see the Nginx welcome page.

Serve Custom HTML

mkdir ~/mysite
echo "<h1>Hello World!</h1>" > ~/mysite/index.html
docker run -d -p 80:80 --name webserver   -v ~/mysite:/usr/share/nginx/html:ro nginx

Use a Custom nginx.conf

docker run -d -p 80:80 --name webserver   -v ~/mysite:/usr/share/nginx/html:ro   -v ~/nginx.conf:/etc/nginx/nginx.conf:ro nginx

Nginx + PHP-FPM with Docker Compose

services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - ./html:/var/www/html
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php

  php:
    image: php:8.2-fpm
    volumes:
      - ./html:/var/www/html

Get SSL with Certbot + Nginx in Docker

docker run -it --rm   -v ~/certbot/conf:/etc/letsencrypt   -v ~/certbot/www:/var/www/certbot   certbot/certbot certonly --webroot   -w /var/www/certbot   -d yourdomain.com

Reload Nginx Config (Without Restart)

docker exec webserver nginx -s reload
  • 0 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

Installing Docker

Installing Docker on Your Dedicated Server Docker allows you to run applications in isolated...

Getting Started with Docker Compose

Getting Started with Docker Compose Docker Compose lets you define and run multi-container...

Managing Docker Containers

Managing Docker Containers A practical reference for day-to-day Docker container management. Run...

Using Docker Volumes for Persistent Storage

Using Docker Volumes for Persistent Storage By default, data inside a container is lost when the...

Docker Networking Explained

Docker Networking Explained Understanding Docker networking lets you connect containers together,...