LoginSignup
0
2

More than 5 years have passed since last update.

DockerでVOLUMEファイルを試す

Last updated at Posted at 2017-08-07

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
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2