What is the difference between docker exec and attach?
The docker container exec command runs a new command in a running container. The command started using docker exec only runs while the container’s primary process (PID 1) is running, and it is not restarted if the container is restarted.
docker exec [OPTIONS] CONTAINER COMMAND [ARG…]
When we start a docker container, we need to decide if we want to run in a default foreground mode or the detached mode.
It will attach local standard input, output, and error streams to a running container.
docker attach [OPTIONS] CONTAINER