How does docker launch a shell session on a minimal Linux installation and immediately dump the container?

I just started using Docker, and I really like it, but I have a clumsy one that I would like to optimize. When I repeat my Dockerfile script I often check things after the build, starting a bash session, running some commands, finding out that such and such a package was not installed correctly, then returning and setting up my Dockerfile.

Say I created my image and marked it as buildfoo, I would run it like this:

$> docker run -t -i buildfoo ... enter some bash commands.. then ^D to exit 

Then I will have a container that I have to empty. Usually I just hook everything like this:

 docker rm --force `docker ps -qa` 

This works well for me. However, I do not need to manually remove the container.

Any advice gratefully accepted!


Some additional small details:

Running a minimal centos 7 image and using bash as my shell.

+5
source share
3 answers

Use the -rm flag of the docker launch command. --rm=true or just --rm .

It automatically deletes the container when it exits (incompatible with -d ). Example:

 docker run -i -t --rm=true centos /bin/bash 

or

 docker run -i -t --rm centos /bin/bash 
+11
source

Although the above still works, the command below uses the new Docker syntax

 docker container run -it --rm centos bash 
+2
source

I use the alias dr

 alias dr='docker run -it --rm' 

This gives you:

 dr myimage ls ... exit 

The container no longer works.

+1
source

Source: https://habr.com/ru/post/1232389/


All Articles