Docker容器构建失败:/ bin / sh:1:烧瓶:找不到

时间:2018-08-26 13:57:04

标签: python docker flask docker-compose

我正在码头化Flask应用程序。要在没有docker的情况下运行该应用程序,我首先运行“ export FLASK_APP = app”,然后运行“ flask run”,因此将其转移到Dockerfile。

这是运行docker-compose -f docker-compose.yml up --build

后的错误消息
  

无法启动服务应用程序:b'OCI运行时创建失败:   container_linux.go:348:启动容器进程引起“执行:   \“烧瓶\”:在$ PATH中找不到可执行文件“:未知”

通过键入docker-compose -f docker-compose.yml logs -f检查日志时,我看到此错误,并且容器退出并显示代码127:

  

/ bin / sh:1:烧瓶:未找到

文件夹结构

tree
  - app
    - __init__.py
  - Dockerfile
  - docker-compose.yml

docker-compose.yml

version: '2' 

services:
  app:
    restart: always
    build: 
      context: .
      dockerfile: Dockerfile
    ports:
      - "5000:5000"
    volumes:
      - .:/app
    depends_on:
      - redis

  redis:
    image: redis
    command: redis-server
    ports:
      - '6379:6379'

Dockerfile

# Pull base image.
FROM ubuntu

# Install Supervisor.
RUN \
  mkdir /var/log/celery && \
  mkdir /home/ubuntu && \
  apt-get update && \
  apt-get install -y supervisor python-pip wget vim git && \
  rm -rf /var/lib/apt/lists/* && \
  sed -i 's/^\(\[supervisord\]\)$/\1\nnodaemon=true/' /etc/supervisor/supervisord.conf

# needs to be set else Celery gives an error (because docker runs commands inside container as root)
ENV C_FORCE_ROOT=1

# expose port 80 of the container (HTTP port, change to 443 for HTTPS)
EXPOSE 80

# Create virtualenv.
RUN \
  pip2 install --upgrade pip && \
  pip install --upgrade virtualenv && \
  virtualenv -p /usr/bin/python2.7 /home/ubuntu/.virtualenvs

WORKDIR /home/ubuntu/celery-scheduler

ADD requirements.txt /home/ubuntu/tree/

# Install app requirements
RUN \
  . /home/ubuntu/.virtualenvs/bin/activate && \
  pip install -r requirements.txt

COPY . /home/ubuntu/tree

# Copy supervisor configs
RUN \
  cp configs/supervisord.conf /etc/supervisor/supervisord.conf && \
  cp configs/conf.d/*.conf /etc/supervisor/conf.d/

ENV FLASK_APP /home/ubuntu/tree/app/
ENV FLASK_DEBUG 1

CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"]

app / __ init __。py

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
import os

db = SQLAlchemy()

def create_app():
    app = Flask(__name__)
    app.config.from_object('config')
    db.init_app(app)

    with app.app_context():
        db.create_all()
    return app

from app import models
app = create_app()
migrate = Migrate(app, db)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)

1 个答案:

答案 0 :(得分:0)

此行:

RUN \
  . /home/ubuntu/.virtualenvs/bin/activate && \
  pip install -r requirements.txt

只会为该特定命令激活您的virtualenv

由于virtualenv激活实际上只能归结为PATH的操作,因此您可以通过ENV

进行操作

这应该有效:

ENV PATH=/home/ubuntu/.virtualenvs/bin:$PATH
RUN pip install -r requirements.txt