2

The docker document says that docker attach is used to attach to a running container (https://docs.docker.com/engine/reference/commandline/attach/) and docker start is used to start stopped containers (https://docs.docker.com/engine/reference/commandline/start/).

However, I tried applying docker start -ai to a running container, and it looks that it can successfully attach to the running container. So my question is "Are docker start -ai and docker attach the same when they are used to attach to a running container?".

1 Answer 1

2

See the code of docker start:

Ln99:  resp, errAttach := dockerCli.Client().ContainerAttach(ctx, c.ID, options)
Ln136: dockerCli.Client().ContainerStart(ctx, c.ID, startOptions)

docker start consists separate attach & start operation, if the container already start, just skip this start operation, but attach still works there.

So, they are same in this scenario. BTW, from October 2014, docker team suggest to use docker exec to enter the container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.