Start a container from desired image like this:
docker run -it --rm image_name bash
-i
Keeps STDIN open even if not attached
-t
Allocates a pseudo-tty
--rm
prunes stopped container after exit
bash
executes the specific command in the container. You can execute any valid command.
Example docker run -it --rm centos:7 pwd
outputs /
(root directory).
Update: In some cases, where image's entrypoint uses bash/sh -c
format above command(docker run -it --rm image_name bash
) will not work because bash
will be treated as additional argument to image's orignal entrypoint.
In such case you can use the --entrypoint
flag for achieving the same result:
docker run -it --entrypoint "/bin/bash" image_name
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…