Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Adding Docker Support #319

wants to merge 2 commits into from

Conversation

bbdoc
Copy link

@bbdoc bbdoc commented Jul 6, 2017

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.

@evenly-epic-mule
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Author

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

Copy link
Author

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.

Copy link

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

Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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 ;)

Copy link
Author

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"]

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.

@DennyLoko
Copy link

DennyLoko commented Jul 6, 2017

What you think about EXPOSE the default port, so automated tools know which port to route?

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 docker-compose.yaml sample file? If you want, I could provide mine and we could work together to adapt it because I don't if is the best practice...

@bbdoc
Copy link
Author

bbdoc commented Jul 11, 2017

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 docker-compose.yaml ? Never used that myself, but why not if it can be useful for some people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants