-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Guides
中文:菜鸟教程:Docker
为了免除各种Python和C++的依赖的复杂配置, 以及避免共用服务器的开发者的开发环境彼此冲 突或污染。
简化在训练机器上的部署和训练。
在以下情景会自动触发GitHub Action:
- Pull Request到Main
- Push了tag
在Pull Request到Main分支时,GitHub Action 会build当前的代码,试图形成一个新的docker image,从而作为PR的检查。如果不能成功build,则 PR的merge会被block。
在push了tag之后,GitHub Action会自动把当前的 版本封装成一个image,推送到liuyunhao1578这个 DockerHub空间中,以tag名作为image的tag,并更新 latest标签,以便于持续部署(CD)。
尚未实现
在PR的时候,还会运行所有的Unit Tests,作为持续 集成(CI)的检查的一部分。
- 不要push到
main - 不要push --force
- 不要合并没有被approve的pull request
- 不要把local的image推送到
liuyunhao1578Docker Hup空间,因为这里保存着 每次自动构建的Docker image,本地的构建需要依赖它们。 - 除非大家都同意,不要prune container或者image
Step 1 更新 Dockerfile
Step 2 docker build -t fyp21011/dev:ericcsr, ericcsr是用来区分container的label。
可以使用任何有意义(或者没有意义)的label,这里用的是创建container的开发者alias。
Step 3 nvdocker run -it -v <src path>:<docker path> ... fyp21011/dev:ericscr /bin/bash.
启动container并把代码仓库的目录<src path>映射到container内部的<docker path>.
Step 4 这样,你就会进入docker进行开发了。不管你在Docker里面docker path目录下做了什么更改,
都会被映射到代码仓库的目录<src path>下。这样,就不用担心失去进度啦
Step 1 更新setup.py(如果有python package依赖的更改)
Step 2 如果上次把container里面的环境ruin了,就nvdocker run重新构建,参照
上面;
其他的话就nvdocker start上次创建container
Step 3 进入container, 如果有更新setup.py,就先pip3 install -e .,再继续测试
Step 4 退出之后,不需要进行commit,只要不prune container就可以,
下次通过nvdocker start继续开发
为了简化上述流程,我们准备了一系列的scripts,只要使用:
./scripts/dev-deploy [image-name]:[tag] [mapping path(s) ...]
# [image-name]: such as the fyp21011/dev mentioned above
# [tag]: such as the ericcsr mentioned above
# mapping paths: the paths ON the host machine need to be mapped into the container
# the script automatically figures out the internal path inside the container
# by default, it will map the entire `PlasticineLab` repository into the container就会:
- 先去自动检查是否有这个
image-name:tag的container的cache,如果有cache,就会问是否要restart这个container,可以选择restart或者rebuild - 如果选择
rebuild,就会去检查是否有这个image- 如果没有这个image,就按照docker file去build这个image,然后再run刚刚build好的新image
- 如果有这个image,就run
- 如果选择restart,就会直接启动cache的container
它会返回被启动的container的id,接下来就可以用nvdocker attach <id> 进入container开发了。