skip to Main Content

Here is my Dockerfile

# Pull node docker image
FROM python:3.7-buster

RUN mkdir -p /home/deployment && chown -R root:root /home/deployment

WORKDIR /home/deployment

COPY weldTrace-linux ./
COPY verified.json ./
COPY flaskapp ./

My docker-compose.yml

    version: "1.0"
services:
  mongo:
    image: mongo:4.4.14
    command: mongod --port 27018
    ports:
      - 27018:27018
    volumes:
      - ${DBPATH}:/data/db
  web:
    build: .
    ports:
      - 3000:3000
    command: ./app-linux
    depends_on:
      - mongo
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ${MEDIAPATH}:/data/media
  flask:
    image: python:3.7-buster
    ports:
      - 5000:5000
    # volumes:
    #   - ${PIPPATH}:/usr/local/lib/python3.7/site-packages
    #   - ./flaskapp:/home/deployment/flaskapp
    # working_dir: /home/deployment/flaskapp
    command: flask run
  #   depends_on:
  #     - requirements
  # requirements:
  #   image: python:3.7-buster
  #   volumes:
  #     - ${PIPPATH}:/usr/local/lib/python3.7/site-packages
  #     - .:/home/deployment/flaskapp
  #   working_dir: /home/deployment/flaskapp
  #   command: pip install -r requirements.txt
volumes:
  data:
    external: true
  pip37:
    external: true

and my PIPPATH=D:Programmingpip37

When I execute docker-compose up, I end up getting the following error

Error response from daemon: failed to create shim: OCI runtime create
failed: container_linux.go:380: starting container process caused:
exec: "flask": executable file not found in $PATH: unknown

Any idea/suggestion about how to fix this? Since Dockerfile base in mongo I could not use RUN command to install any python, pip and its packages.

2

Answers


  1. You need to install Flask in your dockerfile:

    RUN pip install Flask
    
    Login or Signup to reply.
  2. Like others have pointed out, the python:3.7-buster image doesn’t come with flask installed. So flask needs to be installed before the flask run command is executed. For the setup you have, this can be done in one of two ways:

    Option 1:

    As the base image in the Dockerfile is also python:3.7-buster, an instruction can be added to install flask, like Kesha suggested. A slimmed down/customized version of the Dockerfile below:

    FROM python:3.7-buster
    
    RUN mkdir -p /home/deployment && chown -R root:root /home/deployment
    RUN pip install flask
    
    WORKDIR /home/deployment
    
    COPY app.py ./
    

    Then in the docker-compose.yml, the image built for service web can be reused for service flask. Slimmed down compose file below:

    version: "3.3"
    services:
      web:
        build: .
        image: flaskapp:latest
        ports:
          - 3000:3000
        command: echo "Service 'web' exiting.."
      flask:
        image: flaskapp:latest
        ports:
          - 5000:5000
        command: flask run --host=0.0.0.0
        depends_on:
          - web
    

    The flask run command executes without any errors because flask has already been installed into the custom docker image

    Option 2:

    Continue using python:3.7-buster as the image for service flask. In that case, after starting the service, the pip install flask command needs to be executed before the flask run command. Modified compose file below:

    version: "3.3"
    services:
      web:
        build: .
        image: flaskapp:latest
        ports:
          - 3000:3000
        command: echo "Service 'web' exiting.."
      flask:
        image: python:3.7-buster
        ports:
          - 5000:5000
        volumes:
          - ./app.py:/home/deployment/app.py
        working_dir: /home/deployment
        command: 
          - /bin/sh
          - -c
          - |
            pip install flask
            flask run --host=0.0.0.0
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search