반응형
안녕하세요.
오늘은 docker로 nginx를 띄우고 로컬에 있는 html 파일과 매핑해보겠습니다.
1. index.html 파일 생성
index.html 파일입니다.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Docker and Nginx</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>🐳Docker and Nginx에 html 매핑하기🐳</h1>
</body>
</html>
style.css 라는 파일까지 만들어서 html 에 삽입했습니다.
h1 {
text-align: center;
}
2. nginx pull 하기
아래의 명령어를 치면 가장 최신 버전의 nginx를 docker hub에서 받아오게 됩니다.
docker pull nginx
아래 명령어를 통해 nginx 이미지가 다운 받아진 것을 확인할 수 있습니다.
docker images
3. nginx run 하기
docker run -p 8080:80 --rm -d -v C:\Users\User\vscodeProject\docker:/usr/share/nginx/html nginx
-p 8080:80 은 로컬에서 8080으로 접속하면 도커의 80포트와 연결시켜주는 옵션입니다. 저는 지금 로컬에서 80포트에 apache 서버를 쓰고 있어서 8080 포트와 연동시켰습니다.
--rm 은 docker container가 종료되면 삭제한다는 옵션이고, -d는 백그라운드로 실행한다는 옵션입니다.
오늘 포스팅에서 가장 중요한 것은 -v 옵션인데 내 파일들이 들어있는 위치:/usr/share/nginx/html 는 도커에 html 관리하는 폴더와 내 폴더를 연결해주겠다는 뜻입니다.
그러면 결과적으로 이렇게 잘 뜬 것을 확인할 수 있습니다.
반응형
'🌎infra > docker' 카테고리의 다른 글
[Docker] centOS 7 docker mysql 과 spring 연동하기 (한글 깨짐 해결) (1) | 2023.12.21 |
---|---|
[Docker] docker로 nginx와 spring boot 배포하기 (0) | 2023.09.11 |