-
[Docker] Volume 옵션 사용법docker 2024. 8. 31. 00:08
Container 내의 상태
root@e5aec77d1f26:/usr/local/apache2# ls bin build cgi-bin conf error htdocs icons include logs modules root@e5aec77d1f26:/usr/local/apache2# pwd /usr/local/apache2 root@e5aec77d1f26:/usr/local/apache2# cd htdocs root@e5aec77d1f26:/usr/local/apache2/htdocs# pwd /usr/local/apache2/htdocs root@e5aec77d1f26:/usr/local/apache2/htdocs# ls index.html root@e5aec77d1f26:/usr/local/apache2/htdocs# cat index.html <html><body><h1>It works!</h1></body></html> root@e5aec77d1f26:/usr/local/apache2/htdocs#
Local 내의 상태
seotaejun@seotaejuns-Laptop webapp % ls seotaejun@seotaejuns-Laptop webapp % pwd /Users/seotaejun/Desktop/docker_prac/webapp
Container 내에 있는 index.html 파일을 Local 내에 있는 index.html 파일로 대체하고자 한다. 즉 /usr/local/apache2/htdocs 경의 안의 파일들을 local 내의 webapp 폴더 안에 있는 파일들을 공유한다는 것이다. 이럴때는 docker의 volume 옵션을 사용하면 된다.
Volume 옵션
volume 옵션은 특정 디렉토리와 다른 특정 디렉토리를 매핑해준다.
seotaejun@seotaejuns-Laptop webapp % docker run -d -p 8081:80 -v ./:/usr/local/apache2/htdocs httpd
이제 webapp 폴더에 매핑이 되었다. webapp 폴더 안에 아무 파일도 없기 때문에 8081 port에 접속하면 위 사진처럼 보이게 된다.
seotaejun@seotaejuns-Laptop webapp % ls index.html seotaejun@seotaejuns-Laptop webapp % cat index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> Welcome to HTML </body> </html>%
index.html 파일을 넣어주면 이제 index.html 파일 내의 내용이 보이게 된다.
'docker' 카테고리의 다른 글
[Docker] dit옵션과 attach 설명 (0) 2024.08.27 Docker란? (2) 2024.02.28