Docker::Runner
A Docker Runner Cli
Installation
$ gem install docker-runner
$ docker-runner setup
Commands List
$ docker-runner
Usage:
- docker-runner new [project_name] 新建一个镜像
- docker-runner setup 执行环境初始化
- docker-runner reset 重置执行环境
- docker-runner config 查看当前执行环境
- docker-runner build 构建镜像
- docker-runner push 推送镜像到远程仓库
- docker-runner login 登录镜像远程仓库
- docker-runner logout 退出镜像远程仓库
- docker-runner console 开启镜像控制台
- docker-runner clean Docker环境清理
- docker-runner update 更新镜像模板
- docker-runner version 查看当前版本
docker-runner v0.1.0 (c) 2016 @caishuo
使用说明
说明1: 如何制作自己的image
新建一个镜像, 进行项目初始化, 该命令会替你执行:
docker-runner new project_name
该命令会自动执行:
- 设置
username
,image
,version
和镜像简介
等环境变量 - 设置你的Dockerfile
- 重置README.md
- 设置
开始开发
- [可选] rootfs目录会copy到镜像的root目录, 如有需要请添加必要的文件
- [可选] rootfs/init 为
ENTRYPOINT
, 如有需要, 请将容器每次启动的命令写在里面 - 做你想做的
git commit & git push
在本机进行编译, 执行
docker-runner build
编译成功后, 如需进行本地测试, 可以执行
docker-runner console
将镜像push到私有库
docker-runner push
说明2: Docker私有库
- 访问https://portus.caishuo.com/ 注册一个帐号, 统一使用caishuo邮箱, 用户名和邮箱前缀保持一致
- 注册成功后, 则默认拥有私有库(
hub.caishuo.com
)的权限:- 公开库: hub.caishuo.com/:repo 比如 hub.caishuo.com/ruby
- 私有库: hub.caishuo.com/:username/:repo 比如: hub.caishuo.com/wangchangming/ruby
在本地, 登录上你的私有库帐号, 否则没有push权限
docker login hub.caishuo.com
说明3: 如何快速启动Docker容器
添加启动命令的别名
echo 'alias dr="docker run -i -t --rm --name ${NAME:-tmp}"' >> ~/.bash_aliases
将以下代码添加到
~/.bash_profile
if [ "${BASH-no}" != "no" ]; then [ -r ~/.bash_aliases ] && . ~/.bash_aliases fi
执行示例:
dr hub.caishuo.com/ruby /bin/sh # 启动一个name为tmp的容器 dr --name tmp2 hub.caishuo.com/ruby /bin/sh # 启动一个name为tmp2的容器
说明4: 如果远程模版更新了, 如何更新已有项目
- 切换当前工作路径至你的本地项目
执行更新模版
$ docker-runner update
解决冲突后再次commit, 本地的分支便跟上游仓库保持同步了,并且没有丢失你本地的修改。
说明5: 官方镜像加速
Mac
docker-machine ssh default sudo sed -i "s|EXTRA_ARGS='|EXTRA_ARGS='—registry-mirror=https://g7j06i2j.mirror.aliyuncs.com |g" /var/lib/boot2docker/profile exit docker-machine restart default
Ubuntu
echo "DOCKER_OPTS=\"--registry-mirror=https://g7j06i2j.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker sudo service docker restart
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/docker-runner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.