本示例均属于在线安装
所需依赖:
构建Dockerfile
Linux
容器进行构建(alpine linux)alpine 适合用来做Docker镜像、路由器、防火墙、VPNs、VoIP 盒子 以及服务器的操作系统,基于 uClibc 和 Busybox
FROM alpine:3.6
MAINTAINER shenggangshu <[email protected]>
ENV HOME /root
alpine 是使用apk来进行软件包管理的,类似于yum,apt等软件包管理工具。可以很方便的在线安装软件。
由于网络问题,建议使用国内镜像:https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.6/main
更多镜像请查看:https://mirrors.alpinelinux.org/
RUN apk update \
&& apk add --no-cache git gcc libc-dev make automake autoconf libtool pcre pcre-dev zlib zlib-dev openssl-dev wget vim --repository https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.6/main
RUN cd /root \
&& git clone https://github.com/happyfish100/libfastcommon.git --depth 1 \
&& git clone https://github.com/happyfish100/fastdfs.git --depth 1 \
&& wget http://nginx.org/download/nginx-1.15.4.tar.gz \
&& git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
RUN cd ${HOME}/libfastcommon/ \
&& ./make.sh \
&& ./make.sh install
RUN cd ${HOME}/fastdfs/ \
&& ./make.sh \
&& ./make.sh install \
&& cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf \
&& cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf \
&& cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf \
&& cp ${HOME}/fastdfs/conf/http.conf /etc/fdfs/ \
&& cp ${HOME}/fastdfs/conf/mime.types /etc/fdfs/ \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/tracker|g" /etc/fdfs/tracker.conf \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/storage|g" /etc/fdfs/storage.conf \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/storage|g" /etc/fdfs/client.conf
RUN cd ${HOME} \
&& tar -zxvf nginx-1.15.4.tar.gz \
&& cd nginx-1.15.4/ \
&& ./configure --add-module=${HOME}/fastdfs-nginx-module/src/ \
&& make \
&& make install
RUN cp ${HOME}/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs \
&& sed -i "s|^store_path0.*$|store_path0=/var/local/fdfs/storage|g" /etc/fdfs/mod_fastdfs.conf \
&& sed -i "s|^url_have_group_name =.*$|url_have_group_name = true|g" /etc/fdfs/mod_fastdfs.conf \
&& cd ${HOME}/fastdfs/conf/ \
&& echo -e "\
events {\n\
worker_connections 1024;\n\
}\n\
http {\n\
include mime.types;\n\
default_type application/octet-stream;\n\
server {\n\
listen 8888;\n\
server_name localhost;\n\
location ~ /group[0-9]/M00 {\n\
ngx_fastdfs_module;\n\
}\n\
}\n\
}">/usr/local/nginx/conf/nginx.conf
RUN rm -rf ${HOME}/*
# 默认nginx端口
ENV WEB_PORT 8888
# 默认fastdfs端口
ENV FDFS_PORT 22122
# 创建启动脚本
RUN echo -e "\
mkdir -p /var/local/fdfs/storage/data /var/local/fdfs/tracker; \n\
ln -s /var/local/fdfs/storage/data/ /var/local/fdfs/storage/data/M00; \n\n\
sed -i \"s/listen\ .*$/listen\ \$WEB_PORT;/g\" /usr/local/nginx/conf/nginx.conf; \n\
sed -i \"s/http.server_port=.*$/http.server_port=\$WEB_PORT/g\" /etc/fdfs/storage.conf; \n\n\
if [ \"\$IP\" = \"\" ]; then \n\
IP=`ifconfig eth0 | grep inet | awk '{print \$2}'| awk -F: '{print \$2}'`; \n\
fi \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/client.conf; \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/storage.conf; \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/mod_fastdfs.conf; \n\n\
/etc/init.d/fdfs_trackerd start; \n\
/etc/init.d/fdfs_storaged start; \n\
/usr/local/nginx/sbin/nginx; \n\
tail -f /usr/local/nginx/logs/access.log \
">/start.sh \
&& chmod u+x /start.sh
# 暴露端口。改为采用host网络,不需要单独暴露端口
# EXPOSE 80 22122
ENTRYPOINT ["/bin/bash","/start.sh"]
docker-compose.yaml配置
version: '3.0'
services:
fastdfs:
build: .
image: haloo/fastdfs:5.11
# 该容器是否需要开机启动+自动重启。若需要,则取消注释。
#restart: always
container_name: fastdfs
environment:
# nginx服务端口
- WEB_PORT=80
# docker所在主机的IP地址
- IP=192.168.2.222
volumes:
# 将本地目录映射到docker容器内的fastdfs数据存储目录,将fastdfs文件存储到主机上,以免每次重建docker容器,之前存储的文件就丢失了。
- ${HOME}/docker-data/fdfs:/var/local/fdfs
# 使docker具有root权限以读写主机上的目录
privileged: true
# 网络模式为host,即直接使用主机的网络接口
network_mode: "host"
[root@localhost software]# tree
.
└── fdfs
├── docker-compose.yaml
└── Dockerfile
mkdir -p ${HOME}/docker-data/fdfs
docker-compose up -d
docker ps
docker stop <容器NAMES,也可以为容器ID的前几位>
docker-compose stop
docker-compose stop
docker-compose build
docker-compose up -d
一键式构建:
docker-compose up -d --build
docker rm <容器NAMES,也可以为容器ID的前几位>
docker-compose rm
访问fastdfs
所在地址:
192.168.2.222
可以看见,由于docker-compose.yaml
配置的nginx代理地址为80,所以我们可以直接在外部浏览器上直接访问。
在这里不需要进行端口的暴露,因为我们使用的是网络模式为host
,即直接使用主机的网络接口,如果想要开启暴露端口的模式,需要开启EXPOSE 80 22122
docker命令:
docker run -d --name=xxx -p 80:80 <imagesName>:<tag>
FROM alpine:3.6
MAINTAINER shenggangshu <[email protected]>
ENV HOME /root
#安装准备
RUN apk update \
&& apk add --no-cache git gcc gcc-c++ make automake autoconf libtool pcre pcre-dev zlib zlib-dev openssl-dev wget vim --repository https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.6/main
#下载fastdfs.libfastcommon.nginx插件源码
RUN cd /root \
&& git clone https://github.com/happyfish100/libfastcommon.git --depth 1 \
&& git clone https://github.com/happyfish100/fastdfs.git --depth 1 \
&& wget http://nginx.org/download/nginx-1.15.4.tar.gz \
&& git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
# 安装libfastcommon
RUN cd ${HOME}/libfastcommon/ \
&& ./make.sh \
&& ./make.sh install
# 安装fastdfs
RUN cd ${HOME}/fastdfs/ \
&& ./make.sh \
&& ./make.sh install \
&& cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf \
&& cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf \
&& cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf \
&& cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ \
&& cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/tracker|g" /etc/fdfs/tracker.conf \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/storage|g" /etc/fdfs/storage.conf \
&& sed -i "s|/home/yuqing/fastdfs|/var/local/fdfs/storage|g" /etc/fdfs/client.conf
# 获取nginx源码
RUN cd ${HOME} \
&& tar -zxvf nginx-1.15.4.tar.gz \
&& cd nginx-1.15.4/ \
&& ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ \
&& make \
&& make install
# 设置nginx和fastdfs联合环境,并配置nginx
RUN cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs \
&& sed -i "s|^store_path0.*$|store_path0=/var/local/fdfs/storage|g" /etc/fdfs/mod_fastdfs.conf \
&& sed -i "s|^url_have_group_name =.*$|url_have_group_name = true|g" /etc/fdfs/mod_fastdfs.conf \
&& cd ${HOME}/fastdfs/conf/ \
&& echo -e "\
events {\n\
worker_connections 1024;\n\
}\n\
http {\n\
include mime.types;\n\
default_type application/octet-stream;\n\
server {\n\
listen 8888;\n\
server_name localhost;\n\
location ~ /group[0-9]/M00 {\n\
ngx_fastdfs_module;\n\
}\n\
}\n\
}">/usr/local/nginx/conf/nginx.conf
# 清理文件
RUN rm -rf ${HOME}/*
# 配置启动脚本,在启动时中根据环境变量替换nginx端口、fastdfs端口
# 默认nginx端口
ENV WEB_PORT 8888
# 默认fastdfs端口
ENV FDFS_PORT 22122
# 创建启动脚本
RUN echo -e "\
mkdir -p /var/local/fdfs/storage/data /var/local/fdfs/tracker; \n\
ln -s /var/local/fdfs/storage/data/ /var/local/fdfs/storage/data/M00; \n\n\
sed -i \"s/listen\ .*$/listen\ \$WEB_PORT;/g\" /usr/local/nginx/conf/nginx.conf; \n\
sed -i \"s/http.server_port=.*$/http.server_port=\$WEB_PORT/g\" /etc/fdfs/storage.conf; \n\n\
if [ \"\$IP\" = \"\" ]; then \n\
IP=`ifconfig eth0 | grep inet | awk '{print \$2}'| awk -F: '{print \$2}'`; \n\
fi \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/client.conf; \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/storage.conf; \n\
sed -i \"s/^tracker_server=.*$/tracker_server=\$IP:\$FDFS_PORT/g\" /etc/fdfs/mod_fastdfs.conf; \n\n\
/etc/init.d/fdfs_trackerd start; \n\
/etc/init.d/fdfs_storaged start; \n\
/usr/local/nginx/sbin/nginx; \n\
tail -f /usr/local/nginx/logs/access.log \
">/start.sh \
&& chmod u+x /start.sh
# 暴露端口。改为采用host网络,不需要单独暴露端口
# EXPOSE 80 22122
ENTRYPOINT ["/bin/bash","/start.sh"]
fastdfs安装指南
alpinelinux官网网站
Alpine Linux package management
github