6

I installed Docker via snap while setting up Ubuntu Server 18.10.

If I have a systemd unit file that references the docker command, I get this error:

Executable "docker" not found in path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

I'm not sure where it is getting this search path. It does not match what is found in /etc/environment.

Without modifying the unit file, can I globally change the search path used by systemd to include /snap/bin?


On an Ubuntu 18.04 system, just using docker without the full path resulted in the error Executable path is not absolute. I ideally want the same service file to work with both snap's Docker and apt's docker-ce packages.

1
  • If it complained about the relative path even when it found the command in its PATH, it really sounds like the better solution is to modify the unit file. That's also the more portable solution since you'll then be able to copy the unit file to another machine without needing to change systemd's path. Is that really not an option for you? – terdon Feb 26 '19 at 23:37
5

According to the systemd documentation, its PATH is set on compilation (see section "Command lines"):

If the command is not a full (absolute) path, it will be resolved to a full path using a fixed search path determinted at compilation time. Searched directories include /usr/local/bin/, /usr/bin/, /bin/ on systems using split /usr/bin/ and /bin/ directories, and their sbin/ counterparts on systems using split bin/ and sbin/. It is thus safe to use just the executable name in case of executables located in any of the "standard" directories, and an absolute path must be used in other cases. Using an absolute path is recommended to avoid ambiguity. Hint: this search path may be queried using systemd-path search-binaries-default.

The command to query the path on my Ubuntu 18.04 was sudo systemd-path search-binaries (on Arch, it was systemd-path search-binaries-default):

$ sudo systemd-path search-binaries
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

So, you have the following options:

The good: Edit the unit file so that it uses absolute paths. Assuming you have access to it, this is by far the best solution. It makes the file conform to the specification, it allows you to copy it to other machines, it even silences the warning messages.

The bad: Recompile systemd from source, and change the path. This is time consuming, complicated and an all around bad idea unless you really know what you're doing. Even if you do, this seems like a bad solution. You're not going to be able to recompile systemd every time you setup a new machine.

The ugly: If you really can't fix the unit file, you can always create a symlink in /usr/bin pointing to docker

sudo ln -s /snap/bin/docker /usr/bin/docker
3
  • 1
    Thanks. Editing the unit file isn't ideal because I want to distribute my unit file without caring how the system installed Docker (apt or snap, or whatever future package system is dreamt up). But it seems far less intrusive than asking end users to re-compile systemd! – rgov Feb 27 '19 at 18:10
  • 2
    Actually, systemd-path search-binaries reveals /snap/bin is in that list. It does not match the error from systemd. – rgov Feb 27 '19 at 18:18
  • @rgov I have never touched systemd's unit files, so I don't know if this is possible, but perhaps you could do something like if $snapDocker; else $aptDocker? But if you're getting the error even if the dir is in the PATH then it sounds like a proper bug and worth reporting. – terdon Feb 27 '19 at 18:24
4

This is the way to fix this.

To check the value of the variable PATH :

echo $PATH

To add /snap/bin

export PATH="$PATH:/snap/bin"

If this does not work, there is a file called /etc/environment

3
  • 2
    Please read the question more carefully. The OP knows about /etc/environment and the question specifically states this must be fixed without editing the unit file. – terdon Aug 24 '19 at 11:30
  • 2
    I’ll probably make a question and answer with this answer. That was how I got here. I actually had a problem with a different district but we all use Ubuntu for help...:) – Bhikkhu Subhuti Aug 25 '19 at 19:22
  • 1
    Yes, please ask a new question. This answer is about adding snap to a regular user's path, it won't help in the situation the OP describes. It might be a fine answer for another question though! – terdon Aug 25 '19 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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