Container 공부를하며 Docker 플랫폼을 접한지 약 2주가 되었다. 일전에 사놓은 Raspberry Pi 3 B+가 놀고 있어 Dokuwiki를 Docker를 통해 구축하기로 했다. Dokuwiki의 선택은 문서가 RDBMS가 아닌 txt 파일로 저장되며, Raspberry Pi의 성능을 생각해보면 DB로 인한 부하를 주는 것보다는 훨씬 좋겠다고 생각했다. 이런 생각은 Raspberry Pi에는 SSD 128(Samsung 830)이 장착되어있기 떄문이다.
구성 환경
- Raspberry Pi 3 B+
- Raspbian Stretch Lite
- Raspberry Pi에 Docker 설치
root@ysyukr-pi:/usr/local/src# curl -fsSL get.docker.com -o get-docker.sh
root@ysyukr-pi:/usr/local/src# chmod +x get-docker.sh
root@ysyukr-pi:/usr/local/src# ./get-docker.sh
# Executing docker install script, commit: cfba462
+ sh -c apt-get update -qq >/dev/null
+ sh -c apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/raspbian/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=armhf] https://download.docker.com/linux/raspbian stretch stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client:
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:57:21 2018
OS/Arch: linux/arm
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:17:57 2018
OS/Arch: linux/arm
Experimental: false
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
** DOCKER ENGINE - ENTERPRISE **
If you’re ready for production workloads, Docker Engine - Enterprise also includes:
* SLA-backed technical support
* Extended lifecycle maintenance policy for patches and hotfixes
* Access to certified ecosystem content
** Learn more at https://dockr.ly/engine2 **
ACTIVATE your own engine to Docker Engine - Enterprise using:
sudo docker engine activate
root@ysyukr-pi:/usr/local/src# systemctl enable docker
root@ysyukr-pi:/usr/local/src# systemctl start docker
- docker-compose 설치
root@ysyukr-pi:/usr/local/src# apt install docker-compose
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libyaml-0-2 python-backports.ssl-match-hostname python-cached-property python-cffi-backend
python-chardet python-cryptography python-docker python-dockerpty python-docopt python-enum34
python-funcsigs python-functools32 python-idna python-ipaddress python-jsonschema python-mock
python-openssl python-pbr python-pkg-resources python-pyasn1 python-requests python-setuptools
python-six python-texttable python-urllib3 python-websocket python-yaml
Suggested packages:
python-cryptography-doc python-cryptography-vectors python-enum34-doc python-funcsigs-doc
python-mock-doc python-openssl-doc python-openssl-dbg doc-base python-socks python-setuptools-doc
python-ntlm
Recommended packages:
docker.io
The following NEW packages will be installed:
docker-compose libyaml-0-2 python-backports.ssl-match-hostname python-cached-property
python-cffi-backend python-chardet python-cryptography python-docker python-dockerpty
python-docopt python-enum34 python-funcsigs python-functools32 python-idna python-ipaddress
python-jsonschema python-mock python-openssl python-pbr python-pkg-resources python-pyasn1
python-requests python-setuptools python-six python-texttable python-urllib3 python-websocket
python-yaml
0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,723 kB of archives.
After this operation, 8,040 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.harukasan.org/raspbian/raspbian stretch/main armhf python-pkg-resources all 33.1.1-1 [166 kB]
......
Setting up python-openssl (16.2.0-1) ...
Setting up python-docker (1.9.0-1) ...
Setting up docker-compose (1.8.0-2) ...
root@ysyukr-pi:/usr/local/src#
- Dokuwiki 다운로드 및 복사
root@ysyukr-pi:/usr/local/src# wget https://download.dokuwiki.org/out/dokuwiki-b60775a25394d7956e94d100e129e239.tgz
--2019-03-27 23:42:07-- https://download.dokuwiki.org/out/dokuwiki-b60775a25394d7956e94d100e129e239.tgz
Resolving download.dokuwiki.org (download.dokuwiki.org)... 138.201.137.132, 2a01:4f8:172:3483::2
Connecting to download.dokuwiki.org (download.dokuwiki.org)|138.201.137.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2650527 (2.5M) [application/octet-stream]
Saving to: ‘dokuwiki-b60775a25394d7956e94d100e129e239.tgz’
dokuwiki-b60775a25394d7956e94d100e129e239.tgz 100%[====================================================================================================================>] 2.53M 1.02MB/s in 2.5s
2019-03-27 23:42:11 (1.02 MB/s) - ‘dokuwiki-b60775a25394d7956e94d100e129e239.tgz’ saved [2650527/2650527]
root@ysyukr-pi:/usr/local/src# ll
bash: ll: command not found
root@ysyukr-pi:/usr/local/src# ls -al
total 2616
drwxrwsr-x 2 root staff 4096 Mar 27 23:42 .
drwxrwsr-x 10 root staff 4096 Nov 13 12:56 ..
-rw-r--r-- 1 root staff 2650527 Mar 27 23:41 dokuwiki-b60775a25394d7956e94d100e129e239.tgz
-rwxr-xr-x 1 root staff 13070 Mar 27 16:05 get-docker.sh
root@ysyukr-pi:/usr/local/src# tar zxf dokuwiki-b60775a25394d7956e94d100e129e239.tgz
root@ysyukr-pi:/usr/local/src# ls
dokuwiki dokuwiki-b60775a25394d7956e94d100e129e239.tgz get-docker.sh
root@ysyukr-pi:/usr/local/src# mkdir /home/wiki
root@ysyukr-pi:/usr/local/src# mv dokuwiki /home/wiki/public_html
- docker-compose.yml 작성
root@ysyukr-pi:/home/wiki# vi docker-compose.yml
# Auther: ysyukr
version: '2'
services:
wikipf:
# 애석하게도 arm64v8은 3 b+에서 돌아가지 않는다. 어쩔 수 없이 arm32v7로 구성을 한다.
image: arm32v7/php:5.6.40-fpm
# build에 주석처리 된건, 추후 이미지 커스텀이 필요할 때 이용하기 위함
# build:
# context:
# dockerfile: /home/wiki/Dockerfile-php-fpm
volumes:
- /home/wiki/public_html/:/app/
wikix:
image: arm32v7/nginx
# build:
# context: .
# dockerfile: /home/wiki/Dockerfile
ports:
- "8080:80"
volumes:
- /home/wiki/public_html/:/app/
- /home/wiki/config/:/etc/nginx/conf.d/
- nginx가 /app으로 마운트 된 경로를 인식할 수 있도록 default.conf 파일 생성
root@ysyukr-pi:/home/wiki# mkdir config
root@ysyukr-pi:/home/wiki# cd config
root@ysyukr-pi:/home/wiki/config# vi default.conf
server {
listen 80;
server_name localhost;
root /app;
location / {
try_files $uri /index.php$is_args$args;
}
# Dokuwiki 보안을 위한 접근금지 처리
location ~ /(data|conf|bin|inc|vendor)/ {
deny all;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass wikipf:9000; # docker-compose.yml의 php-fpm 이미지의 이름을 기재한다.
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
- docker-compose를 올려서 컨테이너를 실행한다.
root@ysyukr-pi:/home/wiki# docker-compose up -d
Creating wiki_wikix_1
Creating wiki_wikipf_1
root@ysyukr-pi:/home/wiki# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
40344a87a8e9 arm32v7/php:5.6.40-fpm "docker-php-entrypoi…" 3 hours ago Up 2 hours 9000/tcp wiki_wikipf_1
552aed88ebe1 arm32v7/nginx "nginx -g 'daemon of…" 3 hours ago Up 2 hours 0.0.0.0:8080->80/tcp wiki_wikix_1
- Raspberry Pi로 접속해서 dokuwiki가 정상 구동되는지 확인한다.
![image-center]({{ site.url }}{{ site.baseurl }}/assets/images/post/docker-compose-dokuwiki-running.png){: .align-center}