How to execute docker exec commande inside a docker container ?

0 votes

I execute a command inside a docker container :

docker exec -i nullmailer sendmail -f username@gmail.com

The container response is :

the docker command does not exist.

How to execute docker exec command inside a docker container ?

Jul 19, 2018 in Docker by Nilesh
• 6,880 points
378 views

2 answers to this question.

0 votes

If your containers are running on the same host, you can run docker commands inside the container, by exposing the docker socket to the container.

To achieve this, when running the container, mount the docker.sock as such:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

Now you can execute docker commands from within the container.

answered Jul 19, 2018 by Kalgi
• 2,620 points
And for Windows it is:

`docker run -v //var/run/docker.sock:/var/run/docker.sock ...`
Hi @Werner, Can you put this up as an answer? It'll be helpful for other readers. Thank you!
0 votes

You need to get inside the container and then try to execute your command

Follow these steps:

  • Use docker ps to get the name of the existing container

  • Use the command docker exec -it <container name> /bin/bash to get a bash shell in the container

  • Or directly use docker exec -it <container name> <command> to execute whatever command you specify in the container.

answered Aug 13 by Sirajul
• 37,930 points

Related Questions In Docker

0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,870 points
408 views
+1 vote
11 answers

How can I run a ‘docker exec’ command inside a docker container?

Use bash with -c docker exec -it CONTAINER_ID ...READ MORE

answered Dec 10, 2018 in Docker by Kiyara
124,523 views
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,110 points

edited Oct 16, 2018 by lina 5,351 views
0 votes
1 answer

How to continue running a docker container which is already exited?

Restart an existing container after you exited ...READ MORE

answered Jul 19, 2018 in Docker by Sophie may
• 9,870 points
131 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,920 points
226 views
0 votes
1 answer