0
  1. This will create a container named ubuntu_bash and start a Bash session:

docker run --name ubuntu_bash --rm -i -t ubuntu bash

  1. This will create a new file /tmp/execWorks inside the running container ubuntu_bash, in the background:

docker exec -d ubuntu_bash touch /tmp/execWorks

  1. This will create a new Bash session in the container ubuntu_bash:

docker exec -it ubuntu_bash bash

  1. This will create a new Bash session in the container ubuntu_bash with environment variable $VAR set to “1”. Note that this environment variable will only be valid on the current Bash session:

docker exec -it -e VAR=1 ubuntu_bash bash

I did literally followed this steps #1 worked well created a container a put me into the InterActive Shell, but when issue the step #2 into/inside the shell from that Ubuntu container a receive next error:

bash: docker: command not found

In my understanding make sense this error because inside that recently created container doesn't exist docker so it will not recognize any docker-command I issue in it.

Which are my options to make this happen as they stated in this tutorial, below the official docker.com URL: https://docs.docker.com/engine/reference/commandline/exec/

apl
  • 57
  • 1
  • 12
  • 1
    step 1.5 would be to exit the bash shell inside of the container – jordanm Apr 14 '20 at 16:40
  • Also, those examples are not steps, they are independent of each other – jordanm Apr 14 '20 at 16:40
  • Hello @jordanm, thanks for the reply: Actually I use the **exit** command to get out the **Linux Container Shell** and issuing the command in the **Host OS** I receive an error: ~$ sudo docker exec -d ubuntu_bash touch /tmp/execWorks Error: No such container: ubuntu_bash Meaning the container **doesn't exist** I did recreate it without the **rm** option to avoid been destroy after exit it: sudo docker run --name ubuntu_bash -it ubuntu bash And now I'm able to see the path **docker exec -d ubuntu_bash touch /tmp/execWorks** inside of the **ubuntu_bash** container – apl Apr 15 '20 at 08:12
  • Now, what's the purpose of the **docker exec -it -e VAR=1 ubuntu_bash bash**? I know that **-e** is an environment variable, or passing the VAR=1 variable but with which purpose to what for? I'm learning how to use **Linux Container** in Dockers so it is very abstract at the moment for me. – apl Apr 15 '20 at 08:15

0 Answers0