nginx Docker

Docker Nginx,

Syntax

docker run -d -p 80:80 nginx

Parameters

ParametersDescriptionExamplesLevel
-p 80:80 docker run -p 80:80 -p 443:443 nginx Common
-v config -v ./nginx.conf:/etc/nginx/nginx.conf:ro Common
-v html -v ./html:/usr/share/nginx/html:ro Common
--name --name my-nginx Common

Examples

docker run -d --name nginx \
  -p 80:80 \
  -v $(pwd)/html:/usr/share/nginx/html:ro \
  nginx:alpine
alpine ( 40MB)

docker run -d --name nginx \
  -p 80:80 -p 443:443 \
  -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v $(pwd)/conf.d:/etc/nginx/conf.d:ro \
  -v $(pwd)/html:/usr/share/nginx/html:ro \
  -v $(pwd)/certs:/etc/ssl/certs:ro \
  nginx:alpine
, and

Docker Compose

# docker-compose.yml
services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./html:/usr/share/nginx/html:ro
    restart: unless-stopped
Recommended Compose

()

# Dockerfile
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
+ Nginx

Common Errors

Syntax: docker run --rm nginx nginx -t -c /etc/nginx/nginx.conf

Tips

Related Commands