整体思路:
1、官方获取mysql、php+apache镜像;
2、基于php+apache,创建OwnCloud镜像;
3、启动mysql镜像;
4、启动OwnCloud镜像,链接mysql镜像,访问Mysql数据库。
下面开始动手:
一、获取mysql镜像,并启动服务
docker pull mysql:5.7
docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
二、基于php:5.6-apache镜像,创建owncloud镜像(发布owncloud)
1、创建image-owncloud目录;
2、下载owncloud安装包:https://download.owncloud.org/community/owncloud-9.0.1.zip
3、将安装包解压,将其中的owncloud目录整体复制到image-owncloud目录下;
4、在image-owncloud目录下创建init.sh文件,内容如下:
#!/bin/bash
ocpath='/var/www/html'
htuser='www-data'
htgroup='www-data'
rootuser='root' printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs - chmod
find ${ocpath}/ -type d -print0 | xargs - chmod printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/ chmod +x ${ocpath}/occ printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
then
chmod ${ocpath}/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
then
chmod ${ocpath}/data/.htaccess
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi
5、在image-owncloud目录下创建Dockerfile文件,内容如下:
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) mcrypt pdo_mysql\
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
COPY owncloud/ /var/www/html/
COPY init.sh /var/www/html/init.sh
RUN chmod 777 /var/www/html/init.sh
RUN /var/www/html/init.sh
RUN rm /var/www/html/init.sh
5、进入image-owncloud目录下构建owncloud镜像
cd image-owncloud
docker build -t owncloud .
6、启动owncloud镜像
docker run --name owncloud --link mysql:mysql -d -p 80:80 owncloud
7、浏览器中访问http://[宿主机IP],开始初始化owncloud。