Okay, I have been following tutorials online and reading the documentation on Sanic, and I have tried transferring my application to a loosely coded one (functions not contained in a class) to a more strictly coded one (functions contained within a class). I have tried Googling my errors and my problem specifically in many different forms to no avail. I’m somewhat desperate at this point. Please keep in mind that I’m completely new to Docker as well as to Sanic.
So, what is happening is the following:
Toward the goal of creating this distributed data storage system, I am first attempting to code a single “view” or cluster of redundant servers. They should all be available for HTTP requests to the client, and should one of them fail (go down) for any reason, the other servers should be capable of recognizing this. If a server goes down and then comes back up, the server that has come back online is responsible for contacting the other servers in its view, and notifying them of its return to the fold.
So, I am creating a network with docker thusly:
sudo docker network create --subnet=10.10.0.0/16 mynet
Then, I am creating my Docker container image thusly:
sudo docker build -t server .
Then, I am running my containers thusly:
$ sudo docker run -p 8082:8085 --net=mynet --ip=10.10.0.2 --name="replica1" -e SOCKET_ADDRESS="10.10.0.2:8085" -e VIEW="10.10.0.2:8085,10.10.0.3:8085,10.10.0.4:8085" server python3 <name_of_application.py>
$ sudo docker run -p 8083:8085 --net=mynet --ip=10.10.0.3 --name="replica2" -e SOCKET_ADDRESS="10.10.0.3:8085" -e VIEW="10.10.0.2:8085,10.10.0.3:8085,10.10.0.4:8085" server <name_of_application.py>
$ sudo docker run -p 8084:8085 --net=mynet --ip=10.10.0.4 --name="replica3" -e SOCKET_ADDRESS="10.10.0.4:8085" -e VIEW="10.10.0.2:8085,10.10.0.3:8085,10.10.0.4:8085" server python3 <name_of_application.py>
Now, when I run a curl request to the first server that gets spun up, everything works fine. It returns the correct response, i.e., it will return a response in json format with an HTTP status code.
However, when I contact the SECOND server (i.e., send a curl request to it) that gets spun up, that server will NOT return the correct response. Instead, it throws the following error:
Traceback (most recent call last): File “/usr/local/lib/python3.8/site-packages/sanic/app.py”, line 937, in handle_request response = await response File “asgn3_2.py”, line 75, in get return response.json({“message”:“View retrieved successfully”,“view”:returnString}) TypeError: json() takes 1 positional argument but 2 were given
For the love of all that is holy, does anyone have any idea why this is happening? Is it because I’m not running my Docker containers within a virtual environment? Is it because God hates me? If anyone has any help or ideas they can offer, I would be eternally grateful. Thank you in advance.
EDIT: This is the contents of my Dockerfile:
FROM python
COPY /dep.sh /asgn3_2.py /
RUN ./dep.sh
As you can see, the container image will be created with the dependencies that ‘dep.sh’ installs, so here is the contents of the ‘dep.sh’ file:
#!/bin/bash
pip3 install requests
pip3 install simplejson
pip3 install sanic
pip3 install sanic_scheduler