I gave this answer because you were speaking about MySQL and containers without ports.
-e is used to set the environment variable.
I see now that your question is about something else, about the difference between
run -it and
You have to know that a container runs only as long as a foreground process is running inside it. If you start (I use the long syntax and write
-it like ‘interactive terminal’ because it’s easier to remember; not important at all)
docker container run -it google/cloud-sdk
then your terminal gets connected to the container and the process running in the foreground is the one you see at the bottom of the Debian Stretch image:
As soon as you type
exit Bash exits too and the container is terminated. If you run
docker container run -d google/cloud-sdk
Bash has nothing to do and exits immediately together with the container. Check this with
docker container ls -a | grep cloud-sdk
This means if you want to run the cloud-sdk as a daemon so you are able to reconnect to it, add something like
CMD ["tail", "-f", "/dev/null"] at the bottom of your Dockerfile and connect to the running container with
docker container exec -it name-of-my-container bash