Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
"OSError: [Errno 8] Error de formato Exec" al intentar ejecutar la aplicación de matraz simple en un contenedor acoplable

Estoy tratando de iniciar una aplicación Flask "Hello world" simple en un contenedor docker pero sigo recibiendo este error: "OSError: [Errno 8] Exec format error: '/app/app.py'"

Mi sistema operativo anfitrión es Windows 10.

Mi Dockerfile:

 FROM python:3.6 ENV PYTHONBUFFERED 1 ADD . /app WORKDIR /app RUN pip install -r requirements.txt

Tengo requisitos.txt con Flask==1.0.2.

aplicación.py:

 from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == '__main__': app.run(host='0.0.0.0', port=8000, debug=True)

y docker-compose.yml:

 version: '3' services: app: build: . command: python app.py ports: - "8000:8000"

Registro completo del contenedor:

 app_1 | * Serving Flask app "app" (lazy loading) app_1 | * Environment: production app_1 | WARNING: Do not use the development server in a production environment. app_1 | Use a production WSGI server instead. app_1 | * Debug mode: on app_1 | * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit) app_1 | * Restarting with stat app_1 | Traceback (most recent call last): app_1 | File "app.py", line 9, in <module> app_1 | app.run(host='0.0.0.0', port=8000, debug=True) app_1 | File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 943, in run app_1 | run_simple(host, port, self, **options) app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 988, in run_simple app_1 | run_with_reloader(inner, extra_files, reloader_interval, reloader_type) app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader app_1 | sys.exit(reloader.restart_with_reloader()) app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader app_1 | exit_code = subprocess.call(args, env=new_environ, close_fds=False) app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 287, in call app_1 | with Popen(*popenargs, **kwargs) as p: app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 729, in __init__ app_1 | restore_signals, start_new_session) app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 1364, in _execute_child app_1 | raise child_exception_type(errno_num, err_msg, err_filename) app_1 | OSError: [Errno 8] Exec format error: '/app/app.py' flaskdockerproject_app_1 exited with code 1

ACTUALIZAR

Después de agregar el shebang en app.py como dijo @larsks, recibo este error: "FileNotFoundError: [Errno 2] No such file or directory: '/app/app.py': '/app/app.py' .

Todos los archivos están en el contenedor y en el lugar correcto.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Me encontré con el mismo problema (error de formato Exec, luego FileNotFound si agregué el shebang).

Agregar "RUN chmod 644 app.py" al Dockerfile me lo arregló, como se menciona aquí: https://github.com/pallets/werkzeug/issues/1482

over 4 years ago · Santiago Trujillo Report

0

Ayer pasé todo el día reuniendo las piezas de este problema, foro por foro, así que quiero compartir una respuesta más detallada a esta pregunta. Mientras construía mi imagen, también veía el siguiente mensaje de advertencia:

ADVERTENCIA DE SEGURIDAD: Está creando una imagen de Docker desde Windows contra un host de Docker que no es de Windows.

"Se agregó esa advertencia porque el sistema de archivos de Windows no tiene una opción para marcar un archivo como 'ejecutable'. Por lo tanto, crear una imagen de Linux desde una máquina con Windows rompería la imagen si un archivo tiene que marcarse como ejecutable". - https://github.com/moby/moby/issues/20397

Por lo tanto, como señala Richard Chamberlain en el comentario anterior, agregar "EJECUTAR chmod 644.py" garantiza que el archivo app.py esté correctamente marcado.

Al juntar todas las piezas, aquí está el Dockerfile completo que funcionó para mí. ¡Realmente espero que ayude a la próxima persona que lucha con este problema!

 FROM python:3.7-alpine COPY . /app WORKDIR /app RUN apk add --no-cache --virtual .build-deps \ ca-certificates gcc postgresql-dev linux-headers musl-dev \ libffi-dev jpeg-dev zlib-dev \ && pip install --no-cache -r requirements.txt RUN chmod 644 app.py CMD ["python","app.py"]
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!