Run command in stopped container

mmm, ok, There is a fundamental reason why docker containers work like this.

Containers are a set of configuration kernel ‘settings’ that are placed on the application you are running. This means that as far as the Linux kernel is concerned, the container doesn’t exist unless the container’s PID1 is running.

and for that reason, you can’t docker exec into something that doesn’t really exist.

a non-running container (in Docker speak), is really only a set of image layers and some configuration options that will be used when the main application runs.

normally, we’re using echo, sleep and tail as trivial examples - normally, you’d run an a web server as the container’s main process, or an application server, or something like that.

if you want a generalised container environment that you can run anything in - make the ENTRYPOINT a script that exec %ARG (or something like that), and docker run --rm -it myimage mycommand :slight_smile: