1、拉取鏡像
docker pull morunchang/fastdfs
2、運行tracker
docker run -d --name=tracker --net=host morunchang/fastdfs sh tracker.sh
3、運行storage
docker run -d --name=storage --net=host -e TRACKER_IP=<your tacker server address>:22122 -e GROUP_NAME=<group name> morunchang/fastdfs sh storage.sh
- 網絡模式: --net=host 是docker的網絡模式之一:作用是使用和宿主機一樣的ip和端口。
- <your tacker server address> 替換爲你機器的IP。
- <group name> 是組名,即storage的組,我們這裏可以命名爲group1
- 如果想要增加新的storage服務器,再次運行該命令,注意更換新組名
4、修改nginx配置
4.1、進入storage容器內容
docker exec -it storage /bin/bash
4.2、修改nginx.conf配置文件
vim /data/nginx/conf/nginx.conf
添加以下內容:
location /group1/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache http‐cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group1;
expires 30d;
}
5、退出容器並重啓storage容器
exit
docker restart storage
6、設置tracker和storage開啓自啓動
docker update --restart=always tracker
docker update --restart=always storage