You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FROM sanicframework/sanic:LTS
RUN mkdir -p /srv # <-- by adding -p, it will do nothing if the folder already exists
COPY . /srv
WORKDIR /srv # <-- new
EXPOSE 8888
ENTRYPOINT ["python3", "my-sanic-server.py"] # <-- removed /srv/
Rationale
If WORKDIR is not set, all paths referred to in my-sanic-server.py will start from root / instead of /srv. This breaks relative paths in "my-sanic-server.py" when accessing other files in the container or e.g. creating logs.
User story
I modified the Docker file found under base to include SQLAlchemy and copied the equivalent of "my-sanic-server.py" to /srv/ + a SQLite3 database (sample.db). My Python file uses a relative path to access sample.db. I didn't have any problems when running locally, but in a Docker container I was getting errors as: sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: foo.
Originally I thought it was a permission problem ("users" inside a Docker container inheriting the same permissions of the host OS's user with the same UID), but I finally found out that the issue was with the path. It was solved by setting WORKDIR.
mkdir
Also, RUN mkdir /srv in your README to create Docker images based on FROM sanicframework/sanic:LTS does not work, as it gives the error:
The text was updated successfully, but these errors were encountered:
NumesSanguis
changed the title
Include the WORKDIR option in README and mkdir /srv error
Include the WORKDIR option in Dockerfile and mkdir /srv error
Feb 18, 2020
Proposed changes:
Rationale
If
WORKDIR
is not set, all paths referred to inmy-sanic-server.py
will start from root/
instead of/srv
. This breaks relative paths in"my-sanic-server.py"
when accessing other files in the container or e.g. creating logs.User story
I modified the Docker file found under
base
to include SQLAlchemy and copied the equivalent of"my-sanic-server.py"
to/srv/
+ a SQLite3 database (sample.db
). My Python file uses a relative path to accesssample.db
. I didn't have any problems when running locally, but in a Docker container I was getting errors as:sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: foo
.Originally I thought it was a permission problem ("users" inside a Docker container inheriting the same permissions of the host OS's user with the same
UID
), but I finally found out that the issue was with the path. It was solved by settingWORKDIR
.mkdir
Also,
RUN mkdir /srv
in your README to create Docker images based onFROM sanicframework/sanic:LTS
does not work, as it gives the error:The text was updated successfully, but these errors were encountered: