docker exec to run commands inside a running container.docker exec -it webapp bash opens an interactive bash shell inside the running container named webapp. docker run starts a new container, docker start only starts a stopped container without running commands, and docker attach connects to the main process's input/output but does not accept a command argument.
sh if bash is missing.docker exec -it db sh opens an interactive shell using sh inside the running container named db. docker run starts a new container, and docker attach does not accept a command argument.
docker exec -it mycontainer bash but get the error exec: "bash": executable file not found in $PATH. What is the most likely cause?The error means the bash program is missing inside the container. Some minimal images only have sh or other shells. The container being stopped or Docker daemon down would cause different errors. sudo is not always required.
First, docker start app starts the stopped container. Then, docker exec -it app bash opens an interactive shell inside it. docker run creates a new container, and docker attach connects to the main process but does not start the container if stopped.
docker exec -it container_name sh opens a new shell inside the running container, allowing safe debugging without disturbing the main process. docker attach connects to the main process's input/output and can disrupt it. Restarting or stopping the container interrupts service.