I’d like to use Sanic for deploying a MicroService at my workplace.
Since we use Docker + Poetry, I needed to make a “slightly” different Dockerfile than the one suggested in this repo.
Before going to the actual machine that will host everything, I was trying to test the docker build and run process on my windows machine.
This is the Dockerfile that I’ve written
FROM continuumio/anaconda3
ARG YOUR_ENV
ENV YOUR_ENV=${YOUR_ENV} \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
POETRY_VERSION=1.0.0
RUN apt-get update && apt-get install -y --fix-missing gcc mono-mcs
RUN apt-get install -y --fix-missing make
RUN apt-get install -y --fix-missing libpq-dev
# System deps:
RUN pip install "poetry==$POETRY_VERSION"
# Copy only requirements to cache them in docker layer
WORKDIR /code
COPY poetry.lock pyproject.toml /code/
# Project initialization:
RUN poetry config virtualenvs.create false \
&& poetry install $(test "$YOUR_ENV" == production && echo "--no-dev") --no-interaction --no-ansi
# Creating folders, and files for a project:
COPY . /code
EXPOSE 8071
ENTRYPOINT ["python3", "./sanic_starter.py"]
While it correctly builds, when I do the run, it tells me this message
(base) C:\Users\Gianmarco\Desktop\EPICS\AI\Progetti\Dummy\PoCAI>docker run pocai
[2020-07-15 16:35:23 +0000] [1] [INFO] Goin' Fast @ http://localhost:8071
ciao
[2020-07-15 16:35:23 +0000] [1] [ERROR] Unable to start server
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/sanic/server.py", line 886, in serve
http_server = loop.run_until_complete(server_coroutine)
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 583, in run_until_complete
return future.result()
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 1385, in create_server
% (sa, err.strerror.lower())) from None
OSError: [Errno 99] error while attempting to bind on address ('::1', 8071, 0, 0): cannot assign
requested address
[2020-07-15 16:35:23 +0000] [1] [INFO] Server Stopped
And I can’t honestly understand what is going on. Am I, perhaps, forced to deploy with something like gunicorn?
Sanic’s starter has been written in the following way
def run_app(sanic_app: Sanic) -> None:
"""
Utility function to run the sanic application during development.
:param sanic_app: the Sanic application to run.
"""
sanic_app.run(
host=config("HOST", cast=str),
port=config("PORT", cast=str)
)