Docker run, exec, and attach are three separate commands used in managing Docker containers. Here are the differences:
1. Docker run: This command is used to start a new Docker container. With `docker run`, you specify the image you want to use, pass any necessary parameters or environment variables, and it will start a new container based on that image for you. For instance, “docker run ubuntu” will start a new container using the Ubuntu image.
1. Docker exec: This command is used to run a new command in a running Docker container. You specify the Docker container you want to interact with and the command you want to run inside it. For example, “docker exec my\_container ls” would run the `ls` command inside the `my_container` Docker container.
1. Docker attach: This command is used to attach your terminal’s input, output, and error messages to a running Docker container, almost as if you were ssh-ing into it. This allows you to interact with a running Docker container as if it was a separate system. When you’re done, you detach your terminal from the Docker container without stopping it.
Keep in mind that while `docker exec` and `docker attach` may sometimes appear to do similar things, `docker exec` runs a new command in a container, while `docker attach` hooks you into the existing main process of the container. If that process ends, so will your session with the container.