Ah, I think I see what is happening. In your example, the
echo one command exits immediately, which stops the container.
docker exec only works with currently running containers.
If you want to take the resulting image, and run another command, you will need to commit that and start another container.:
$ docker run --name mycont4 ubuntu echo one
$ docker commit mycont4 myimage5
$ docker run --name mycont5 myimage5 echo two
Since the echo example might be skewing a bit,
docker exec may still work for you. For example:
$ docker run --name mycont4 ubuntu sleep 10 # let this exit
$ docker start mycont4 $ this starts sleep 10 back up in the background
$ docker exec mycont4 ps faux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 8 0.0 0.1 15568 2112 ? R 08:11 0:00 ps faux
root 1 0.7 0.0 4348 648 ? Ss 08:11 0:00 sleep 10
Since sleep doesn’t exit immediately, the container is running still when you run
Hopefully this is helpful.