Docker快速搭建OpenStack Swift开发环境

从 docker hub 下载docker镜像 docker-swift-onlyone 在本地运行:

ID=$(docker run -d -p 12345:8080 --volumes-from SWIFT_DATA -t morrisjobke/docker-swift-onlyone)

查看启动日志:

docker logs $ID

使用默认测试用户查看状态:

swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing stat

测试文件上传:

swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing upload swift swift.txt

测试下载

swift -A http://127.0.0.1:12345/auth/v1.0 -U test:tester -K testing download swift swift.txt

另外,在 github bouncestorage/docker-swift 看到可以获取用户的auth token,使用Rest API来对Swift访问。

curl -v -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' 

输出:

http://127.0.0.1:12345/auth/v1.0
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 12345 (#0)
> GET /auth/v1.0 HTTP/1.1
> Host: 127.0.0.1:12345
> User-Agent: curl/7.47.0
> Accept: */*
> X-Storage-User: test:tester
> X-Storage-Pass: testing
> 
< HTTP/1.1 200 OK
< X-Storage-Url: http://127.0.0.1:12345/v1/AUTH_test
< X-Auth-Token: AUTH_tk1f1e14601ef346f4883d5efb6c34e1e0
< Content-Type: text/html; charset=UTF-8
< X-Storage-Token: AUTH_tk1f1e14601ef346f4883d5efb6c34e1e0
< Content-Length: 0
< X-Trans-Id: txa513a51ac53e4ce0b0798-00575cd375
< Date: Sun, 12 Jun 2016 03:13:57 GMT
< 

使用上一步得到的X-Auth-Token和 X-Storage-Url 可以访问,也可以将这两个值作为环境变量TOKENURL,方便后续的的使用。

curl -v -H 'X-Auth-Token: AUTH_tk1f1e14601ef346f4883d5efb6c34e1e0' http://127.0.0.1:12345/v1/AUTH_test

输出:

*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 12345 (#0)
> GET /v1/AUTH_test HTTP/1.1
> Host: 127.0.0.1:12345
> User-Agent: curl/7.47.0
> Accept: */*
> X-Auth-Token: AUTH_tk1f1e14601ef346f4883d5efb6c34e1e0
> 
< HTTP/1.1 204 No Content
< Content-Type: text/plain; charset=utf-8
< X-Account-Object-Count: 0
< X-Timestamp: 1465701356.73964
< X-Account-Bytes-Used: 0
< X-Account-Container-Count: 0
< X-Put-Timestamp: 1465701356.73964
< Content-Length: 0
< X-Trans-Id: txdd3f4112ed19411fbac58-00575cd3ec
< Date: Sun, 12 Jun 2016 03:15:56 GMT
< 
* Connection #0 to host 127.0.0.1 left intact

更多操作可以参照 github,比如其中的demo.sh,其中X-Auth-Token和 X-Storage-Url 对应环境变量TOKENURL

echo Create container

curl -X PUT -i -H "X-Auth-Token: $TOKEN" $URL/testcontainer

echo List containers:

curl -X GET -i -H "X-Auth-Token: $TOKEN" $URL

echo Contents of container:

curl -X GET -i -H "X-Auth-Token: $TOKEN" $URL/testcontainer

echo Metadata of container:

curl -X HEAD -i -H "X-Auth-Token: $TOKEN" $URL/testcontainer

echo Put object:

curl -X PUT -i -H "X-Auth-Token: $TOKEN" -T demo.sh $URL/testcontainer/testobject

echo Retrieve object

curl -X GET -i -H "X-Auth-Token: $TOKEN" -o retrieved_demo.sh $URL/testcontainer/testobject

当然,用以上 git hub 里提到的镜像 kahing/docker-swift 也可以

作者:happeace
链接:https://www.jianshu.com/p/f7c3c45cb4b1
來源:
著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

你可能感兴趣的:(Docker快速搭建OpenStack Swift开发环境)