Nitraqu의 블로그

nitraqu.egloos.com

포토로그



[Docker] Host - Docker 디렉터리 공유

1. HTTPD Docker 이미지 받기 
nitraqu@ubuntu:~$ docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
7a6db449b51b: Pull complete
b4effd428409: Pull complete
6b29c2b62286: Pull complete
c2123effa3fc: Pull complete
152876b0d24a: Pull complete
Digest: sha256:b418eccc8ec9a04dc07596aef200edfa4d2020dc1168654d6a17af145c33cae6
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest

* httpd:latest 에는 Apache2 서버가 설치되어 있다. 

1.1 이미지 다운로드 확인
nitraqu@ubuntu:~$ docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest a981c8992512 2 weeks ago 145MB



2. 실행 
nitraqu@ubuntu:~$ docker run -it -p 9000:80 --name my-httpd httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Tue Sep 13 02:24:05.665769 2022] [mpm_event:notice] [pid 1:tid 140436019174720] AH00489: Apache/2.4.54 (Unix) configured -- resuming normal operations
[Tue Sep 13 02:24:05.665926 2022] [core:notice] [pid 1:tid 140436019174720] AH00094: Command line: 'httpd -D FOREGROUND'
172.17.0.1 - - [13/Sep/2022:02:24:19 +0000] "GET / HTTP/1.1" 200 45
172.17.0.1 - - [13/Sep/2022:02:24:19 +0000] "GET /favicon.ico HTTP/1.1" 404 196
* -p 9000:80  : 호스트의 9000번과 docker 컨테이너의 80을 맵핑.

2.1. 실행 결과 확인





3. Host 의 볼륨을 Docker Container에 연결하기 

3.1. index.html 만들기 
nitraqu@ubuntu:~/www/html$ pwd
/home/nitraqu/www/html
nitraqu@ubuntu:~/www/html$ cat index.html
<html><body><h1>It works? </h1></body></html>

3.2 docker에 host의 디렉터리 연결 (-v 옵션 사용)  
nitraqu@ubuntu:~$ sudo docker run -dit -p 9100:80 -v /home/nitraqu/www/html:/usr/local/apache2/htdocs --name my-httpd2 httpd

* -v [host]:[container] : 호스트의 특정 디렉터리를, 컨테이너의 특정 디렉터리로 사용해라. 심볼릭 링크 비슷? docker iimage는 그대로 두고, 외부에서 특정 파일만 수정하고자 할 때 유용. 


3.3. 실행 확인
 
* 해당 IP는 Host(Ubuntu)의 IP 임. 사실 Ubuntu도 VMware에서 동작중.. 





덧글

댓글 입력 영역