Search code examples
dockerdockerfileapachebench

File not exists in Docker container


I have a docker container running and the file structure looks as below.

enter image description here

My work directory is '/app' and I have copied all files into it from my local system. Basically, I want to run Apache Bench with SSL support and hence I have copied these 3 files as well into the workdir.

  • abs.exe
  • libcrypto-1_1-x64.dll
  • libssl-1_1-x64.dll

My DockerFile looks as below

FROM python:3.7

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY ./ /app

WORKDIR /app

CMD [ "python", "ab_script.py"]

and in the file ab_script.py, I am invoking the script

subprocess.Popen(['abs', '-n 100', '-c 10', 'https://my-url.com'], 
                           stdout=subprocess.PIPE,
                           universal_newlines=True)

Though it runs completely fine on my local, I getting the below error when I execute it from Docker.

Traceback (most recent call last):
  File "ab_script.py", line 70, in <module>
    cold_start_process = start_cold_start_process()
  File "ab_script.py", line 28, in start_cold_start_process
    universal_newlines=True)
  File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'abs': 'abs'

Even though I have placed the file abs.exe in the workdir, it says that the file is not found. Could anyone please let me know where I might be going wrong? Thanks.


Solution

  • If the file is called abs.exe then subprocess.Popen(['abs', ...]) is never going to find it. Even if you correct the filename, it still won't work because your current directory is generally not searched for binary names. You would need to provide an explicit path with the correct name, such as:

    subprocess.Popen(['./abs.exe', '-n 100', '-c 10', 'https://my-url.com'], 
                               stdout=subprocess.PIPE,
                               universal_newlines=True)