Docker. How to get bash\ssh inside running container (run -d)?


$ sudo docker attach 665b4a1e17b6 #by ID
$ sudo docker attach loving_heisenberg #by Name
$ root@665b4a1e17b6:/# 

UPDATE: (docker >= 1.3) Thanks to WiR3D user who suggested another way to get container’s shell. If we use attach we can use only one instance of shell. So if we want open new terminal with new instance of container’s shell, we just need run the following:

$ sudo docker exec -i -t 665b4a1e17b6 bash #by ID
$ sudo docker exec -i -t loving_heisenberg bash #by Name
$ root@665b4a1e17b6:/#



Precedence for the Commandline $PATH

On the commandline the elements of PATH are checked from left to right.

an example (PATH)

the command which exists in

for the following path


the /usr/bin/ gets precedence.

bash redirect output STDOUT STDERR

HOWTO redirect output: STDOUT / STDERR


output or stdout to screen
$ echo "test"

redirects stdout to afile.txt
$ echo "test" > afile.txt

  • 0 is stdin.
  • 1 is stdout.
  • 2 is stderr.

also redirects stdout to afile.txt
$ echo "test" 1> afile.txt

redirect stderr to afile.txt
$ echo "test" 2> afile.txt

>& is the syntax to redirect a stream to another file descriptor

redirect stdin to stderr
$ echo "test" 1>&2
# or
$ echo "test" >&2

..or vice versa:

$ echo "test" 2>&1

So, in short.. 2> redirects STDERR to an (unspecified) file, appending &1 redirects STDERR to STDOUT