Docker Community Forums

Share and learn in the Docker community.

Docker container can't find a file, although it just listed it with ls

I am having a very weird issue to where my docker container tells me it’s unable to execute a file because it can’t find it; however, I restructured my Dockerfile so that it’s running an ls in that directory to find the file. Based on the output during the docker build, the file actually exists, so I can’t quite understand why it’s not able to run it on the very next line.

Here’s a snippet from my Dockerfile:

    # Replace systemctl with a working one
    git clone /opt/systemctl-github && \
    rm /usr/bin/systemctl && \
    ln -s /opt/systemctl-github/files/docker/ /usr/bin/systemctl && \
    dpkg -i /tmp/ssm/amazon-ssm-agent.deb && \
    ls -lh /usr/bin/systemctl && \
    systemctl stop amazon-ssm-agent && \

However, when building the container, I see the following error:

Cloning into '/opt/systemctl-github'...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 30.7M  100 30.7M    0     0  14.5M      0  0:00:02  0:00:02 --:--:-- 14.5M
lrwxrwxrwx 1 root root 47 Dec 14 22:20 /usr/bin/systemctl -> /opt/systemctl-github/files/docker/
/bin/sh: 1: /opt/systemctl-github/files/docker/ not found

Can’t seem to figure out any reason as to why this wouldn’t work.

It is probably python2 which is not found, not the script. The script you used is based on python2 which is not really supported anymore so it is probably missing from your image.

Try with the other script: docker-systemctl-replacement/ at 9cbe1a00eb4bdac6ff05b96ca34ec9ed3d8fc06c · gdraheim/docker-systemctl-replacement · GitHub

It uses python3. Make sure you have python3 installed in your image.

I also have a tutorial on how you can run systemd in a container. GitHub - itsziget/tutorial-linux-signals at 48ac221303c48dc5b03197d4b1e65fd00fc1dffa

That systemd replacement repository is a bit old. Systemd has changed a lot since then so running systemd in a container became easier.

1 Like

Ahh, I see. You’re right. I had Python3 installed and removed kali-linux-defaults from the Dockerfile, so I guess Python2 was no longer being installed, thus causing this issue. After switching the script to the version ending in 3, seems to work just fine. Error message was just extremely weird.

Thanks for the help!