[英]how to “docker run” a shell session on a minimal linux install and immediately tear down the container?
I just started using Docker, and I like it very much, but I have a clunky workflow that I'd like to streamline. 我刚开始使用Docker,我非常喜欢它,但我有一个笨重的工作流程,我想简化。 When I'm iterating on my Dockerfile script I will often test things out after a build by launching a bash session, running some commands, finding out that such and such package didn't get installed correctly, then going back and tweaking my Dockerfile.
当我在我的Dockerfile脚本上进行迭代时,我会经常在构建之后通过启动bash会话,运行一些命令,发现这样的包没有正确安装,然后返回并调整我的Dockerfile来测试。
Let's say I have built my image and tagged it as buildfoo, I'd run it like this: 假设我已经构建了我的图像并将其标记为buildfoo,我会像这样运行它:
$> docker run -t -i buildfoo
... enter some bash commands.. then ^D to exit
Then I will have a container running that I have to clean up. 然后我将有一个容器运行,我必须清理。 Usually I just nuke everything like this:
通常我只是像这样对待一切:
docker rm --force `docker ps -qa`
This works OK for me.. However, I'd rather not have to manually remove the container. 这对我来说没问题。但是,我宁愿不必手动删除容器。
Any tips gratefully accepted ! 感谢任何提示!
Some Additional Minor Details: 一些额外的小细节:
Running minimal centos 7 image and using bash as my shell. 运行最小的centos 7图像并使用bash作为我的shell。
Please use -rm
flag of docker run command. 请使用
-rm
run命令的-rm
标志。 --rm=true
or just --rm
. --rm=true
或只是--rm
。
It automatically remove the container when it exits (incompatible with -d
). 它会在退出时自动删除容器(与
-d
不兼容)。 Example: 例:
docker run -i -t --rm=true centos /bin/bash
or 要么
docker run -i -t --rm centos /bin/bash
尽管上面的命令仍然有效,但下面的命令使用了Docker的新语法
docker container run -it --rm centos bash
I use the alias dr
我用别名
dr
alias dr='docker run -it --rm'
That gives you: 这给你:
dr myimage
ls
...
exit
No more container running. 没有更多的容器在运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.