Is there a difference in "connecting" to the container via docker attach or docker exec?

0

My question is: is there a difference in "connecting" to a container using the statement docker attach and docker exec -it container /bin/bash ?

My container was created like this: docker run -it -p 80:80 --name dev debian:stretch /bin/bash

I came to read some posts about this subject, as far as I could understand, docker attach is an instruction used to connect to the container without opening a new process, that is, it connects to the shell instantiated when the container was created. / p>

If I run: docker exec -it container /bin/bash I'll be creating a new process.

As docker is a reasonably new world for me, I'm not sure if this understanding is correct.

    

asked by anonymous 14.01.2018 / 13:49

1 answer

1

The docker exec is used to send a command to the container in question, when you do docker exec -it container /bin/bash a statement is sent to the container to open a bash process and keep it open until it closes. Looking at the documentation you can better understand this.

While docker attach attaches the stdio of the container to your terminal, it's as if you used an ssh, this is written in documentation .

In any case, if you want to view the logs of a container use docker logs . If you want to run a command in the container, create a dockerfile , because the container idea is to be reusable and if you do the command with the container running, when you restart it (possibly it will happen), you will need to do the command again.

    
15.01.2018 / 12:40