-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Docker Support #319
base: develop
Are you sure you want to change the base?
Conversation
I think it would be nice if you could provide a config.py / accounts.csv, which is then mounted inside the container, so that they don't have to be part of the image it self |
# docker build -t Monocle | ||
# docker run -d --name Monocle -P Monocle | ||
|
||
FROM python:3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python:3.6-alpine3.6
could be worth trying to reduce the size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try to build it with alpine but was running into some missing requirements to install monocle packages so fell back on the full python:3.6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean with providing a config.py / accounts.csv. It doesn't need to be part of the image, you can easily have those files in a local folder and user docker run -v option in order to share those files between your local filesystem and docker container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also try with :alpine, but I had a mistake with the pogeo requirement.
This is my current working docker file :
FROM python:3.6.0-slim
WORKDIR /usr/src/app
ENV DUMP_INIT_VERSION 1.2.0
ENV TERM=xterm
RUN buildDeps='build-essential ca-certificates curl' \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends -y $buildDeps python3-cairo libmysqlclient-dev libgeos-dev supervisor \
&& curl -sLo /tmp/dumb-init.deb https://github.com/Yelp/dumb-init/releases/download/v"$DUMP_INIT_VERSION"/dumb-init_"$DUMP_INIT_VERSION"_amd64.deb \
&& dpkg -i /tmp/dumb-init.deb \
&& pip install --upgrade pip \
&& pip install --no-cache-dir pymysql
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
COPY optional-requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r optional-requirements.txt
# Cleanup
RUN apt-get purge -y --auto-remove $buildDeps \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY . /usr/src/app/
EXPOSE 5000 6000
ENTRYPOINT ["/usr/bin/dumb-init"]
CMD ["/usr/bin/supervisord", "-c", "supervisord.conf"]
And my supervisord.conf
:
[supervisord]
nodaemon=true
[program:scan]
command=python scan.py
startsecs=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:web]
command=python web.py --host 0.0.0.0
startsecs=5
And my docker CMD :
docker run -d \
--restart=always \
--name pogomap \
-p 6000:6000 \
-v $path/accounts.csv:/usr/src/app/accounts.csv \
-v $path/config.py:/usr/src/app/monocle/config.py \
-v $path/landmarks.pickle:/usr/src/app/pickles/landmarks.pickle \
-v $path/supervisord.conf:/usr/src/app/supervisord.conf \
--link maria_db \
registry.gitlab. . ./monocle:prod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the accounts.pickle could be a thing, too
as if you don't have your phone IDs in the accounts.csv they would be generated everytime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add it in the description but I guess people using docker know they need to provide a persistent working directory on the local filesystem if they want anything persistent... so indeed I also pass a -v option with a working directory for pickles, logs, ... That's more something we would need to describe in a wiki than in the dockerfile itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a lot of people who know what docker is and may get it started, but acually have no idea of what they are doing ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this gets committed, I'll update the wiki with some recommandations and examples on how to launch Monocle inside a docker container... guess they are other things to talk about (e.g. creating a docker network and run a db inside a docker with persistency on local filesystem) so better tackle all those stuff on the wiki for people who would like to start with Docker ;-)
Dockerfile
Outdated
WORKDIR /usr/src/app | ||
|
||
# Set Entrypoint with hard-coded options | ||
ENTRYPOINT ["python3", "./scan.py"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to suggest to change to ENTRYPOINT ["python3"]
and add CMD ["./scan.py"]
, so we could start a web instance only changing the command, not the whole entrypoint.
What you think about Also, I would install every major dependency, like MySQL and Postgres libs, so anyone could just run this Docker image out-of-the-box. Also, what you think about adding a |
EXPOSE has been added and Entrypoint has been split into Entrypoint + CMD. Not sure about adding major dependencies. I'm just following Monocle's way of thinking here, and as far as he decided to add like MySQL in optional requirements, why add it as a default requirement in Dockerfile ? What's the purpose of adding a |
Adding a basic Dockerfile for people willing to run Monocle within a Docker container.
Please note that default entrypoint is "scan.py". This means if launching container with default options, it will launch the Monocle scanner. For launching the web.py or any of the tools, entrypoint will need to be overwriten in the docker run command, e.g. for the web interface:
`--entrypoint '/usr/src/app/web.py'
or for any tool available in Monocle's script directory :
--entrypoint '/usr/src/app/scripts/print_levels.py
Dockerfile also installs "libgeos-dev" as it's required by "shapely" which in turn is required to run multipolygons. It was not tested with other optional requirements, only shapely and mysqlclient.