Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker exec or docker container exec

Tags:

docker

I noticed in the latest Docker CLI documentation that Docker CLI command list has expanded. If I used docker exec earlier to start executable inside container now I can also use docker container exec command.

docker container run command is similar to docker run, etc.

So which commands are preferrable now? Old syntax or new docker container syntax? Unfortunately I couldn't find any explanation in the docs.

Also what is the difference between docker container run and docker container create commands? And between docker container stop and docker container kill? The description and syntax are very similar.

Thanks.

like image 634
Sergiy Avatar asked Oct 23 '17 20:10

Sergiy


People also ask

What is the Docker exec?

Docker exec is a command that allows the execution of any given command within a Docker container. This means it will interpret the arguments passed to it as commands to be run inside the container.

What is the difference between docker run and Docker exec?

What's the Difference between Docker Run and Docker Exec? Docker Run vs Docker Exec! This is a fairly common question – but has a simple answer! In short, docker run is the command you use to create a new container from an image, whilst docker exec lets you run commands on an already running container!

Why do we use Docker exec?

The exec command is used to interact with already running containers on the Docker host. It allows you to start a session within the default directory of the container. Sessions created with the exec command are not restarted when the container is restarted.


1 Answers

As docker grew in features over time and new commands were added cli needed some redesign. You should use docker container exec to be compatible in the future, but docker exec is in fact an alias so until someone decided to deprecate it should also work. If you are interested, you can start reading about this change from this PR: https://github.com/moby/moby/pull/26025

like image 181
odk Avatar answered Oct 24 '22 11:10

odk