# docker-compose零成本搭建一个ipfs图床取代telegraph图床 **Published by:** [it备忘录](https://paragraph.com/@it-3/) **Published on:** 2024-09-08 **URL:** https://paragraph.com/@it-3/docker-compose-ipfs-telegraph ## Content 拉取前端代码git clone https://github.com/img2ipfs/img2ipfs部署ipfs节点创建 docker-compose.yaml 文件。version: '3.8' services: ipfs: image: ipfs/kubo restart: unless-stopped volumes: - ./ipfs:/data/ipfs environment: - IPFS_PATH=/data/ipfs ports: # p2p 通信端口 - 4001:4001/tcp - 4001:4001/udp # API 端口 - 127.0.0.1:5001:5001 # HTTP 网关端口 - 127.0.0.1:8080:8080 caddy: image: caddy restart: unless-stopped ports: - "8080:8080" - "443:443" - "80:80" volumes: - ./img2ipfs:/app - ./Caddyfile:/etc/caddy/Caddyfile - ./caddy_data:/data - ./caddy_config:/config depends_on: - ipfs 请根据情况自己修改域名、端口这些。 Caddyfile# 图片网关代理,可以不要,白嫖别人的 http://i1.img2ipfs.com { reverse_proxy ipfs:8080 } # 上传接口 只给上传文件这个接口,其它不给 http://api.img2ipfs.org { reverse_proxy /api/v0/add ipfs:5001 { } } # 网站前端 http://img2ipfs.org { root * /app @static { file path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.webp } header @static Cache-Control max-age=31536000 encode gzip zstd } ipfs的数据保存在当前目录的 ipfs 里面。 启动节点docker-compose up,让节点初始化,然后关闭节点。 编辑 ipfs/config 文件,增加跨站访问权限。{ "API": { "HTTPHeaders": { "Access-Control-Allow-Origin": [ "https://cdn.ipfsscan.io", "*" ] } } } 你可以只设置自己的域名,也可以设置为 * 。修改前端代码修改 static/file.js 第79行的API上传接口,其它想改的地方也可以修改。启动docker-compose up -d 。ipfs图床的优势存储空间和流量成本很低,白嫖了大量其它网关和节点。通过这种方式上传的图片,不会被压缩,也不会被打码,100%原图。不会因为网站停止运行导致图片丢失,你随时可以换一个ipfs网关。图片看的人越多,图片被复制到的节点越多,越可靠。ipfs图床的劣势冷门图片加载速度慢,甚至可能丢失(一年以上没有人看)样例展示https://cdn.ipfsscan.io 原文: https://blog.chenjia.info/posts/2024/08/docker-compose%E9%9B%B6%E6%88%90%E6%9C%AC%E6%90%AD%E5%BB%BA%E4%B8%80%E4%B8%AAipfs%E5%9B%BE%E5%BA%8A%E5%8F%96%E4%BB%A3telegraph%E5%9B%BE%E5%BA%8A/ ## Publication Information - [it备忘录](https://paragraph.com/@it-3/): Publication homepage - [All Posts](https://paragraph.com/@it-3/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@it-3): Subscribe to updates