0

I've been struggling to get a Docker image up and running on Windows 10 Home, using Docker Toolbox. Here is the error that I see in Kitematic:

python: can't open file 'src/__main__.py': [Errno 2]   
No such file or directory

This Python command that is failing is the entry point for the 'notes' Docker container.

After Docker/up.sh the process finishes without any errors.

Successfully built f59c275721cf
Successfully tagged docker_mysql:latest
Creating mysql ... done
Creating notes ... done

Additionally, this is a group project in which other users on Macs aren't able to duplicate this error. After updating Dockerfile to below and running:

Successfully built 42a95cd419f2
Successfully tagged docker_mysql:latest
Creating mysql ... done
Creating notes ... done

User@DESKTOP-EBUI9GE MINGW64 /c/users/user/Desktop/6440/Procedure-Notes-Application (master)
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
68f60fdba6f5        docker_mysql        "docker-entrypoint.s…"   15 seconds ago      Up 9 seconds        0.0.0.0:23306->3306/tcp   mysql

User@DESKTOP-EBUI9GE MINGW64 /c/users/user/Desktop/6440/Procedure-Notes-Application (master)
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                     NAMES
e7fbd5b73189        docker_notes        "python /app/src/__m…"   23 seconds ago      Exited (2) 17 seconds ago                             notes
68f60fdba6f5        docker_mysql        "docker-entrypoint.s…"   23 seconds ago      Up 17 seconds               0.0.0.0:23306->3306/tcp   mysql

Updated Dockerfile:

### Use an official Python runtime as a parent image 
FROM python:2.7-slim

### set working directory to the code location
WORKDIR /app

### copy the code base over (redone by the compose file)
COPY . .

### Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

### Make port available to the world outside this container
EXPOSE 5000

### start the application
CMD ["python", "/app/src/__main__.py"]

I am now getting another error:

 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "/app/src/__main__.py", line 57, in <module>
    app.run(debug=True, host='0.0.0.0')
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 943, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 988, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/usr/local/lib/python2.7/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/usr/local/lib/python2.7/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
    exit_code = subprocess.call(args, env=new_environ, close_fds=False)
  File "/usr/local/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/local/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/local/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
5
  • How was the container created? Is it possible you have a volumes entry that mounts from a local directory that you don't have, or perhaps bad ADD/WORKDIR in the Dockerfile?
    – harrymc
    Mar 26, 2019 at 19:54
  • I have posted the Dockerfile in the edit above Mar 26, 2019 at 20:32
  • You don't need mkdir, as WORKDIR will create it. It's also better to use absolute references, such as WORKDIR /app and CMD ["python", "/app/src/__main__.py"].
    – harrymc
    Mar 26, 2019 at 20:50
  • I tried your suggestion with the same result as before I have edited the post to reflect the results. Looks like the image runs briefly before exiting. Mar 26, 2019 at 22:09
  • I'm getting another error, latest edit the bottom of the post. Mar 26, 2019 at 23:00

1 Answer 1

0

My first remark, that let the process start was:

You don't need mkdir, as WORKDIR will create it. It's also better to use absolute references, such as WORKDIR /app and CMD ["python", "/app/src/__main__.py"].

The Python script now starts and stops the error:

  File "/usr/local/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception

This is typically an error in the Python script. One possibility is described in the post python subprocess.call() not working as expected:

By default subprocess.call doesn't use a shell to run our commands you so can't shell commands like cd.

To use a shell to run your commands use shell=True as parameter. In that case it is recommended to pass your commands as a single string rather than as a list. And as it's run by a shell you can use ~/ in your path, too:

subprocess.call("(cd ~/catkin_ws/src && catkin_make)", shell=True)
1
  • Thank you kindly. I realized I was having issues with the volume section in my compose file. After fixing that I added a line in the Dockerfile to give execution permission to main, and it seems to be working after that, but because Volumes wont work I'm having to rebuild every time. Mar 30, 2019 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .