6

I'm learning about docker and I cannot seem to cd into the docker folder. I'm in etc folder and I'm trying to enter docker folder. It's blue text indicating it's a directory and I am able to enter into other blue directorys.

DIR_COLORS               makedumpfile.conf.sample  ssh
DIR_COLORS.256color      man_db.conf               ssl
DIR_COLORS.lightbgcolor  mime.types                statetab
dnsmasq.conf             mke2fs.conf               statetab.d
dnsmasq.d                modprobe.d                subgid
docker                   modules-load.d            subuid
dracut.conf              motd                      sudo.conf
dracut.conf.d            mtab    

I even try sudo cd docker.
But when I do this, the command line does nothing. I can ls the folder to see it's contents as below:

[user@bucephalus1 etc]$ sudo ls -al docker
total 16
drwx------.   2 root root   21 Mar 22 01:07 .
drwxr-xr-x. 103 root root 8192 Mar 24 10:57 ..
-rw-------.   1 root root  244 Mar 22 01:07 key.json

But I cannot cd into docker as seen below:

[user@bucephalus1 etc]$ sudo ls -al docker
total 16
drwx------.   2 root root   21 Mar 22 01:07 .
drwxr-xr-x. 103 root root 8192 Mar 24 10:57 ..
-rw-------.   1 root root  244 Mar 22 01:07 key.json
[user@bucephalus1 etc]$ sudo cd docker
[user@bucephalus1 etc]$

Does anyone have any idea on what is happening here?

2 Answers 2

14

It's normal and caused by the perms of the /etc/docker folder, as mentioned in your question:

[user@bucephalus1 etc]$ sudo ls -al docker
total 16
drwx------.   2 root root   21 Mar 22 01:07 .
(...)

because this folder belongs to root and have permissions 700.

You can instead do:

$ sudo su -
root:~# cd /etc/docker
root:/etc/docker# 

Note however that modifying this folder might be error-prone and I'm unsure there's any use case requiring to do it.

Furthermore, this related answer from askubuntu.com gives more details on sudo su -:
"sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used"

2
6

In addition to what the previous answer said, some background on the cd command:

When you cd, you should get this error:

$ cd /etc/docker/
bash: cd: /etc/docker/: Permission denied

When you sudo cd /etc/docker/, you are likely to get an error like this:

$ sudo cd /etc/docker
sudo: cd: command not found

But I guess there could be distros where you don't get that, and there actually is a cd binary. However, this binary should never work, because it would change the shell's child process' current directory (i.e. the current directory of the cd process), rather than the shell's current directory.

Maybe try doing which cd and executing the result. You will most likely see that you cannot change directories with this binary, even if you do not use sudo.

So use e.g. sudo -s to get a root shell and then cd around.

1
  • Yeah you might be right @sneep. This distro, centOS, doesn't seem to be giving me the "command not found" feedback. It just resets to the commandline prompt. Thanks for your help too.
    – Bucephalus
    Commented Mar 24, 2018 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.