docker
volume

DockerでVOLUMEファイルを試す

More than 1 year has passed since last update.

This is how we setup docker
dockerのセットアップは、こちらを見て下さい

I will implemt this structure.

スクリーンショット 2017-08-07 16.19.30.png

Create dockerfile for a volume

Dockerfile
FROM centos:latest
MAINTAINER 0.1 joji@test.com
RUN ["mkdir", "/var/log/httpd"]
VOLUME /var/log/httpd

Create image

bash
sudo docker build -t log-volume-image .

check it

bash
sudo docker images | grep log
#log-volume-image    latest              ea4362acfb12        11 minutes ago      193MB

Create dockerfile for Apache

Dockerfile
FROM centos
MAINTAINER taro yamada <taro.yamada@bibo.com.ph>
# RUN: It executes when it is built
RUN yum -y install httpd
EXPOSE 80
# CMD: It executes when it is running
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
bash
sudo docker build -t httpd-image .

check it

bash
sudo docker images | grep httpd
#httpd-image         latest              8d1d89cb6ce4        34 seconds ago      332MB

start container for log

bash
sudo docker run -it --name log-container log-volume-image

start container for httpd

bash
sudo docker run -d --name httpd-container \
                          -p 8080:80 \
                          --volumes-from log-container httpd-image

start another container for httpd. The difference is just name and port.

bash
sudo docker run -d --name httpd-container-2 \
                          -p 8081:80 \
                          --volumes-from log-container httpd-image

You can access here

browser
http://192.168.55.44:8080/
http://192.168.55.44:8081/

check log file. attach container

bash
sudo docker start -ia log-container

You can see a log file by this command

bash
tail -f /var/log/httpd/access_log

You can check also in httpd server.

bash
sudo docker exec -it httpd-container /bin/bash
bash
tail -f /var/log/httpd/access_log