Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (11.4k points)

When I try to run the following command I get an error :

docker exec -i nullmailer sendmail -f [email protected]


This shows the following error:

the docker command does not exist

5 Answers

+2 votes
by (32.3k points)

Just keep in mind that running the containers on the same host will give you the privilege of executing docker commands within the container. You can do this just by defining the docker socket in the container.

Simply run the container and mount the 'docker.sock':

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

Finally, execute docker commands from inside the container.

by (29.5k points)
Thanks this helped!!!
by (44.4k points)
Mounting and running from inside the container worked for me.
by (47.2k points)
In order to make debugging easier, we are introduced with docker exec, which allows a user to spawn a process inside their Docker container via the Docker API and CLI.
+1 vote
by (108k points)

The first thing you need to do is to get inside the container and then try to execute your command.

Follow these steps:

  • Use docker ps to see the name of the existing container.
  • Then 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.
by (19.7k points)
This helped me!
+2 votes
by (29.3k points)

For this, you can run the container inside a container using its id

sudo docker exec -it <container-id> bin/bash

you can use -d option as well. 

by (33.1k points)
Thanks for this clear answer.
It worked for me.
by (32.1k points)
I tried mounting inside the container. It worked for me. You can try that as well.
0 votes
by (19.9k points)

You can do it like this:

docker start <container_id/container_name> && docker attach <container_id/container_name> 

0 votes
by (106k points)

To run a command on an already existing Docker container by running below-mentioned command but you have to be knowing its ID (or name):

docker exec -it <container_id_or_name> echo "Hello from container!"

Another point to note that exec command works only on already running container. If the container is currently stopped, then you will need to run it first with the following command:

docker run -it -d shykes/pybuilder /bin/bash

The most important thing to keep in mind here is the -d option, which stands for detached. It means that the command you initially provided to the container (/bin/bash) will be run in the background and the container will not stop immediately.

Browse Categories

...