검증된 문서입니다
클라우드 서버를 생성하여 이 문서의 명령을 처음부터 끝까지 그대로 실행하고 확인한 문서입니다.
- 운영체제
- Ubuntu 26.04.1 LTS · x86_64
- 설치 버전
- Docker 29.9.2, Docker Compose 5.6.1, nginx:1.30 image (Nginx 1.30.6)
- 테스트 서버
- DigitalOcean · 1 vCPU / 2 GB RAM / 50 GB SSD (s-1vcpu-2gb, sgp1)
- 마지막 확인
- 2026-10-27
이 문서에는 제휴 링크가 포함되어 있습니다. 링크를 통해 가입하면 코드샌드가 일정 수수료를 받을 수 있으며, 문서 내용과 평가에는 영향을 주지 않습니다.
Ubuntu 26.04 서버에서 Docker Compose로 Nginx 1.30 공식 이미지를 실행하는 방법을 정리합니다. compose.yaml 작성, 페이지 폴더와 설정 폴더 연결, 로그 확인, 설정을 바꾼 뒤 다시 읽게 하는 방법, 재시작 정책, 자주 만나는 오류와 삭제하는 방법까지 다룹니다.
1. 준비물
- Docker와 Docker Compose가 설치된 Ubuntu 26.04 LTS 서버 1대 (Ubuntu 26.04에 Docker 설치하는 방법 참고)
sudo없이docker명령을 쓸 수 있는 일반 사용자 계정 (docker그룹)- 서버에 Nginx가 직접 설치되어 있지 않아야 합니다 (80 포트를 함께 쓸 수 없습니다)
서버가 없다면 DigitalOcean의 Droplet(1 vCPU · 2GB)을 생성해 보세요. 이 문서의 모든 과정은 Droplet(1 vCPU · 2GB 메모리 · 50GB SSD · Ubuntu 26.04 · 싱가포르)으로 서버를 생성하고, Docker 공식 저장소로 설치한 Docker 29.9.2와 Docker Compose 5.6.1, 일반 사용자 계정으로 확인했습니다. 외부 접속은 다른 PC(예시 IP 203.0.113.10)에서 서버(예시 IP 203.0.113.20)로 확인했습니다.
docker --versionDocker version 29.9.2, build a82e528docker compose versionDocker Compose version v5.6.12. 프로젝트 폴더와 파일 만들기
프로젝트 폴더 안에 웹 페이지를 둘 html 폴더와 Nginx 설정을 둘 conf.d 폴더를 만듭니다. 두 폴더는 컨테이너 안의 폴더와 연결해서 씁니다. 컨테이너를 지우고 다시 만들어도 이 두 폴더의 파일은 그대로 남습니다.
mkdir -p ~/nginx-compose/html ~/nginx-compose/conf.d && cd ~/nginx-compose && pwd/home/devuser/nginx-compose첫 페이지를 만듭니다. 출력은 없습니다.
echo '<h1>Hello from Docker Nginx</h1>' > ~/nginx-compose/html/index.htmlNginx 사이트 설정을 만듭니다. 컨테이너 안에서 /etc/nginx/conf.d 폴더의 .conf 파일을 읽기 때문에, 이 파일이 이미지에 들어 있는 기본 설정(default.conf)을 대신하게 됩니다. 출력은 없습니다.
cat > ~/nginx-compose/conf.d/default.conf <<'EOF'
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
EOFcompose.yaml을 만듭니다. 출력은 없습니다.
cat > ~/nginx-compose/compose.yaml <<'EOF'
services:
nginx:
image: nginx:1.30
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html:ro
- ./conf.d:/etc/nginx/conf.d:ro
restart: unless-stopped
EOFimage: nginx:1.30: Docker Hub의 Nginx 공식 이미지 중 1.30 계열(안정 버전)을 씁니다.nginx:latest처럼 버전을 적지 않으면 새로 받을 때마다 버전이 바뀔 수 있습니다.ports: "80:80": 서버의 80 포트로 들어온 요청을 컨테이너의 80 포트로 넘깁니다.volumes: 왼쪽은 서버 폴더, 오른쪽은 컨테이너 안의 폴더입니다.:ro는 컨테이너가 이 폴더를 읽기만 하고 고치지 못한다는 뜻입니다.restart: unless-stopped: 컨테이너가 꺼지거나 서버가 재부팅되면 다시 실행합니다. 직접 멈춘(docker compose stop) 경우는 제외합니다. 6단계에서 확인합니다.
cd ~/nginx-compose && find . -type f | sort./compose.yaml
./conf.d/default.conf
./html/index.html3. 컨테이너 실행
compose.yaml이 있는 폴더에서 실행합니다. -d는 컨테이너를 백그라운드에서 실행하고 터미널을 바로 돌려준다는 뜻입니다. 처음 실행할 때는 아래 결과 앞에 nginx:1.30 이미지를 내려받는 줄(Pulling, Pulled)이 먼저 표시됩니다.
docker compose up -d[+] up 2/2
✔ Network nginx-compose_default Created 0.1s
✔ Container nginx-compose-nginx-1 Started 0.5sSTATUS가 Up이고 PORTS에 0.0.0.0:80->80/tcp가 있으면 정상입니다.
docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx 2 seconds ago Up 1 second 0.0.0.0:80->80/tcp, [::]:80->80/tcpcurl -i http://localhostHTTP/1.1 200 OK
Server: nginx/1.30.6
Date: Tue, 27 Oct 2026 08:45:58 GMT
Content-Type: text/html
Content-Length: 33
Last-Modified: Tue, 27 Oct 2026 08:45:43 GMT
Connection: keep-alive
ETag: "6ae064b7-21"
Accept-Ranges: bytes
<h1>Hello from Docker Nginx</h1>컨테이너 안의 Nginx 버전도 확인할 수 있습니다. docker compose exec는 실행 중인 컨테이너 안에서 명령을 실행한다는 뜻입니다.
docker compose exec nginx nginx -vnginx version: nginx/1.30.6PC(203.0.113.10)에서도 접속합니다.
curl http://203.0.113.20<h1>Hello from Docker Nginx</h1>sudo ufw statusStatus: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)4. 로그 확인
Nginx 공식 이미지는 접속 로그와 오류 로그를 파일이 아니라 컨테이너 출력으로 내보냅니다. 그래서 docker compose logs로 봅니다. 앞부분은 컨테이너가 시작할 때의 기록이고, 마지막 두 줄이 서버 안과 PC에서 보낸 요청입니다.
docker compose logs nginxnginx-1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx-1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx-1 | 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
nginx-1 | /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx-1 | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: using the "epoll" event method
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: nginx/1.30.6
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: built by gcc 14.2.0 (Debian 14.2.0-19)
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: OS: Linux 7.0.0-31-generic
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:524288
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: start worker processes
nginx-1 | 2026/10/27 08:45:56 [notice] 1#1: start worker process 21
nginx-1 | 172.18.0.1 - - [27/Oct/2026:08:45:58 +0000] "GET / HTTP/1.1" 200 33 "-" "curl/8.18.0" "-"
nginx-1 | 203.0.113.10 - - [27/Oct/2026:08:46:05 +0000] "GET / HTTP/1.1" 200 33 "-" "curl/8.7.1" "-"4번째 줄의 can not modify … (read-only file system?)는 오류가 아닙니다. 이미지가 시작할 때 기본 설정에 IPv6 설정을 넣으려 하는데, 설정 폴더를 :ro로 연결했기 때문에 건너뛰었다는 안내입니다. 서버 안에서 보낸 요청은 Docker 내부 주소(172.18.0.1)로 기록됩니다.
마지막 몇 줄만 보려면 --tail을 씁니다. -f를 붙이면(docker compose logs -f nginx) 새 로그가 생길 때마다 계속 표시하고, Ctrl+C로 멈춥니다.
docker compose logs --tail 2 nginxnginx-1 | 172.18.0.1 - - [27/Oct/2026:08:45:58 +0000] "GET / HTTP/1.1" 200 33 "-" "curl/8.18.0" "-"
nginx-1 | 203.0.113.10 - - [27/Oct/2026:08:46:05 +0000] "GET / HTTP/1.1" 200 33 "-" "curl/8.7.1" "-"5. 설정 바꾸고 다시 읽게 하기
html 폴더의 페이지 파일은 바꾸는 즉시 반영됩니다. 설정 파일은 Nginx가 다시 읽어야 반영됩니다. 상태 확인용 주소(/health)를 추가해 봅니다. 출력은 없습니다.
cat > ~/nginx-compose/conf.d/default.conf <<'EOF'
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
location = /health {
default_type text/plain;
return 200 "ok\n";
}
}
EOF컨테이너 안의 Nginx로 설정에 오류가 없는지 먼저 확인합니다.
docker compose exec nginx nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful컨테이너를 다시 시작하지 않고 설정만 다시 읽게 합니다. 접속 중인 요청은 끊기지 않습니다.
docker compose exec nginx nginx -s reload2026/10/27 08:46:21 [notice] 35#35: signal process startedcurl http://localhost/healthok6. 재시작 정책 확인
컨테이너에 적용된 재시작 정책을 확인합니다.
docker inspect -f "{{.HostConfig.RestartPolicy.Name}}" nginx-compose-nginx-1unless-stopped서버를 재부팅한 뒤 다시 접속해 확인합니다. uptime -p는 서버가 켜진 지 얼마나 되었는지 보여 줍니다. 서버가 켜진 지 1분이 안 되었는데 컨테이너가 다시 실행되어 있습니다.
sudo systemctl rebootuptime -pup 0 minutescd ~/nginx-compose && docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx 48 seconds ago Up 1 second 0.0.0.0:80->80/tcp, [::]:80->80/tcpcurl http://203.0.113.20/healthokdocker compose stop으로 직접 멈춘 컨테이너는 재부팅해도 다시 실행되지 않습니다.
docker compose stop Container nginx-compose-nginx-1 Stopping
Container nginx-compose-nginx-1 Stopped이 상태에서 재부팅한 뒤 확인한 결과입니다. -a는 멈춘 컨테이너까지 보여 준다는 뜻입니다.
docker compose ps -aNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx About a minute ago Exited (0) 42 seconds ago다시 실행하려면 docker compose up -d를 실행합니다.
7. 문제 해결
nginx: [emerg] invalid number of arguments in "default_type" directive
설정 파일에 문법 오류가 있다는 뜻입니다. 아래는 default_type text/plain; 줄 끝의 세미콜론을 지운 뒤 확인한 결과입니다. default.conf:14는 오류가 있는 파일과 줄 번호입니다.
docker compose exec nginx nginx -t2026/10/27 08:46:30 [emerg] 42#42: invalid number of arguments in "default_type" directive in /etc/nginx/conf.d/default.conf:14
nginx: [emerg] invalid number of arguments in "default_type" directive in /etc/nginx/conf.d/default.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failednginx -s reload는 실패하고 Nginx는 이전 설정으로 계속 실행됩니다. 하지만 이 상태로 docker compose restart를 하면 Nginx가 시작하지 못해 컨테이너가 계속 다시 시작됩니다(Restarting).
docker compose restart nginx Container nginx-compose-nginx-1 Restarting
Container nginx-compose-nginx-1 StartedStarted로 표시되지만 몇 초 뒤 상태를 보면 Restarting입니다.
docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx 45 seconds ago Restarting (1) 1 second ago이때는 사이트에 접속할 수 없고, 로그 마지막 줄에 원인이 표시됩니다.
docker compose logs --tail 3 nginxnginx-1 | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx-1 | 2026/10/27 08:46:40 [emerg] 1#1: invalid number of arguments in "default_type" directive in /etc/nginx/conf.d/default.conf:14
nginx-1 | nginx: [emerg] invalid number of arguments in "default_type" directive in /etc/nginx/conf.d/default.conf:14표시된 줄을 고친 뒤 docker compose restart nginx를 실행하세요. 설정을 바꿀 때는 restart보다 5단계처럼 nginx -t로 확인하고 nginx -s reload를 쓰면 이런 중단을 막을 수 있습니다.
Error response from daemon: Container … is restarting, wait until the container is running
컨테이너가 계속 다시 시작되는 중이라 docker compose exec를 쓸 수 없다는 뜻입니다.
docker compose exec nginx nginx -tError response from daemon: Container c82c8472b36530ebcbdd1c857b43d7c29a56038fa7b513a7f6cd34f32a914afa is restarting, wait until the container is running설정 파일을 고친 뒤에는 docker compose run으로 임시 컨테이너를 만들어 설정을 확인할 수 있습니다. --rm은 확인이 끝나면 임시 컨테이너를 지운다는 뜻이고, --no-deps는 다른 서비스를 함께 실행하지 않는다는 뜻입니다. 앞부분의 시작 기록은 생략했습니다.
docker compose run --rm --no-deps nginx nginx -t…
/docker-entrypoint.sh: Configuration complete; ready for start up
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful확인이 끝나면 docker compose restart nginx로 다시 시작합니다.
docker compose restart nginx Container nginx-compose-nginx-1 Restarting
Container nginx-compose-nginx-1 Starteddocker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx About a minute ago Up 3 seconds 0.0.0.0:80->80/tcp, [::]:80->80/tcpfailed to bind host port 0.0.0.0:80/tcp: address already in use
서버의 80 포트를 다른 프로그램이 쓰고 있다는 뜻입니다. 아래는 다른 프로그램(파이썬 웹 서버)이 80 포트를 쓰는 상태에서 실행한 결과입니다.
docker compose up -dError response from daemon: failed to set up container networking: driver failed programming external connectivity on endpoint nginx-compose-nginx-1 (0ccae67bcbf725b9d64756697d4bc6273e741d20df19fa92e7df2a8c7685f9c0): failed to bind host port 0.0.0.0:80/tcp: address already in usesudo ss -tlnp | grep ":80 "로 80 포트를 쓰는 프로그램을 찾아 끄거나, compose.yaml의 ports를 "8080:80"처럼 다른 포트로 바꾸세요.
포트를 비운 뒤에는 꼭 docker compose up -d를 다시 실행하세요. 이 서버에서는 실패 직후 up -d를 한 번 더 실행했을 때 컨테이너가 포트 연결 없이 실행되었습니다. STATUS는 Up인데 PORTS 칸이 비어 있고, 접속도 되지 않습니다.
docker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx 19 seconds ago Up 16 seconds포트를 비운 상태에서 docker compose up -d를 실행하면 컨테이너를 다시 만들고(Recreate) 포트가 연결됩니다.
docker compose up -d Container nginx-compose-nginx-1 Recreate
Container nginx-compose-nginx-1 Recreated
Container nginx-compose-nginx-1 Starting
Container nginx-compose-nginx-1 Starteddocker compose psNAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginx-compose-nginx-1 nginx:1.30 "/docker-entrypoint.…" nginx 1 second ago Up Less than a second 0.0.0.0:80->80/tcp, [::]:80->80/tcp8. 삭제하기
컨테이너와 Compose가 만든 네트워크를 지웁니다. html 폴더와 conf.d 폴더의 파일은 서버에 있으므로 지워지지 않습니다.
cd ~/nginx-compose
docker compose down Container nginx-compose-nginx-1 Stopping
Container nginx-compose-nginx-1 Stopped
Container nginx-compose-nginx-1 Removing
Container nginx-compose-nginx-1 Removed
Network nginx-compose_default Removing
Network nginx-compose_default Removed내려받은 Nginx 이미지를 지웁니다.
docker image rm nginx:1.30Untagged: nginx:1.30
Deleted: sha256:a7675fcee220f59b4a99f7098c06a0d5d999c2c0ee37c0211efb780536e5cb20프로젝트 폴더를 지웁니다. 출력은 없습니다.
cd ~
rm -rf ~/nginx-compose남은 컨테이너와 이미지가 없는지 확인합니다.
docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdocker imagesIMAGE ID DISK USAGE CONTENT SIZE EXTRA직접 해 보기
서버가 없다면 아래 업체에서 몇 분이면 Ubuntu 서버를 만들 수 있습니다. 이 문서는 DigitalOcean 에서 검증했습니다.
이 문서가 도움이 됐나요? 틀린 곳이나 바뀐 내용이 있으면 알려 주세요.
내용 정정 요청