IPFS Series - Experience IPFS Docker

docker enables an ipfs node and connects to the public network ipfs network

https://hub.docker.com/r/ipfs/go-ipfs

# [推荐] 挂载本地路径
export ipfs_staging=~/devcontainer/IPFS/staging
export ipfs_data=~/devcontainer/IPFS/data
docker run -d --name ipfs_host -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 4001:4001/udp -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

    ## -d 后台运行容器
    ## -it 运行容器并attch进去
    ## --rm 关闭容器时自动删除

# 临时文件, 关掉不保存
docker run --rm -it  -p 4001:4001/tcp -p 4001:4001/udp -p 5001:5001/tcp -p 8080:8080/tcp -p 8081:8081/tcp ipfs/go-ipfs:latest

control Panel

http://127.0.0.1:5001/webui

upload files

#先进入ipfs_host容器内
docker exec -it ipfs_host sh

cd ~
touch ~/testIpfs.txt
ipfs add ~/testIpfs.txt
# added QmT97x7DczJ3VzB4iVMc9bk3P5db3rou1chEtBWx7MF8Vk testIpfs.txt

download file

ipfs get QmT97x7DczJ3VzB4iVMc9bk3P5db3rou1chEtBWx7MF8Vk -o testIpfs.txt

upload folder

cd ~
mkdir testFolder
touch ~/testFolder/empty.txt
ipfs add -r ~/testFolder
# added QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH testFolder/empty.txt
# added QmUCqFurfVHz1emCsW6cpLoLbGK9pTEGcEmM5yjvDKnAk3 testFolder

Downloads folder (use the unique id of the folder returned above)

ipfs get QmUCqFurfVHz1emCsW6cpLoLbGK9pTEGcEmM5yjvDKnAk3 -o testFolder

View the file just uploaded through the api

https://ipfs.io/ipfs/QmUCqFurfVHz1emCsW6cpLoLbGK9pTEGcEmM5yjvDKnAk3

https://ipfs.io/ipfs/QmUCqFurfVHz1emCsW6cpLoLbGK9pTEGcEmM5yjvDKnAk3/empty.txt

Even if the container is turned off, you can still view the files uploaded before downloading

You can also install the chrome plugin: IPFS Companion
https://chrome.google.com/webstore/detail/ipfs-companion/nibjojkomfdiaoajekhjakgkdhaomnch

Guess you like

Origin blog.csdn.net/wcc19840827/article/details/127741048