[Docker] 5. Mount

문정준's avatar
Jul 30, 2025
[Docker] 5. Mount

컨테이너에 미리 작성된 파일을 마운트

  • 마운트 : 이미지가 바라보는 ROOT를 내 PC의 폴더로 설정 가능
    • 파일을 복사하지 않고 경로를 변경
    • image 세팅을 그대로 사용하면서 내부 파일만 변경할 수 있음 : 상태 수정 및 저장 가능
notion image

httpd

  • 포트포워딩을 통해 접속 시 해당 index.html로 진입
docker run -dit -p 8080:80 httpd
notion image
 

index.html 위치 확인

  • bash로 내부 폴더 진입
# docker ps -q : 실행 중인 컨테이너 id docker exec -it $(docker -ps -q) bash
 
 

index.html 변경

  • C:\workspace\docker-lab\ex01 폴더 안에 변경할 html 작성
notion image
 

Volume (바인드 마운트)

  • 내가 ex01 폴더 안에 만든 index.html을 바라보게 만들기 위해 아래 명령어 입력
    • 경로 작성 시 PowerShell은 Windows 경로는 역슬래시 (git bash는 슬래시)
docker run -d -p 8000:80 -v C:\workspace\docker-lab\ex01:/usr/local/apache2/htdocs httpd
 
notion image
 

NginX 사용 시

  • html 파일은 /usr/share/nginx/html 폴더 안에 있음
notion image
 
  • nginx를 바인드 마운트
docker run -d -p 8000:80 -v C:\workspace\docker-lab\ex01:/usr/share/nginx/html nginx
notion image
notion image
 
Share article

sxias