'Docker image runs on heroku server but not locally
I have a docker image that runs as expected from Heroku, but breaks when I try to run the image locally. When I run the image locally, I am not able to stop the image or open the Docker CLI. When I repeatedly hit stop, the container exits with a code of 137
. I run the command docker build -t generate_test_service
. from the project directory and simply press play from the Docker application.
Dockerfile
# start by pulling the python image
FROM alpine:latest
# copy the requirements file into the image
COPY ./requirements.txt /app/requirements.txt
# switch working directory
WORKDIR /app
# install the dependencies and packages in the requirements file
RUN apk update
RUN apk add py-pip
RUN apk add --no-cache python3-dev
ENV VIRTUAL_ENV=./venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --upgrade pip
RUN apk add --update gcc libc-dev linux-headers && rm -rf /var/cache/apk/*
RUN pip install psutil
RUN pip --no-cache-dir install -r requirements.txt
# copy every content from the local file to the image
COPY . /app
# configure the container to run in an executed manner
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
EXPOSE 4000
app.py
from flask import Flask
from flask import jsonify
import os
app = Flask(__name__)
if __name__ == '__main__':
port = os.environ.get("PORT", 5000)
app.run(debug=False, host='0.0.0.0', port=port)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|