简体   繁体   中英

create a dockerfile to run python and groovy app

I am working on a project which is using both python and groovy to scrap data from websites and do some engineering on that data.

I want to create a dockerfile which should have a python(3.6.5) as base image and java8 and groovy should be installed on it to run my code.

the dockerfile I have right now is working for all the python codes(image : FROM python:3.6.5) but failing for groovy script and I cant find a solution which I can use to install groovy in dockerfile.

is there anyone who has a dockerfile solving this part problem ?

####docker file below
FROM python:3.6.5 RUN sh -c "ls /usr/local/lib" RUN sh -c "cat /etc/*-release" # Contents of requirements.txt each on a separate line for incremental builds RUN pip install SQLAlchemy==1.2.7 RUN pip install pandas==0.23.0 RUN pip uninstall bson RUN pip install pymongo RUN pip install openpyxl==2.5.3 RUN pip install joblib RUN pip install impyla RUN sh -c "mkdir -p /src/dateng" ADD . /src/dateng RUN sh -c "ls /src/dateng" WORKDIR /src/dateng/ ENTRYPOINT ["python", "/src/dateng/_aws/trigger.py"]

You don't need to use sh -c command , just RUN command and we should not use a RUN instruction per command, intead we should group them in only one RUN , because each RUN is a separated layer in the docker image, thus increasing the final size of it.

Possible Solution

Inspired in this Dockerfile I use for a Python demo:

FROM python:3.6.5

ARG CONTAINER_USER="python"
ARG CONTAINER_UID="1000"

# Will not prompt for questions
ENV DEBIAN_FRONTEND=noninteractive \
    CONTAINER_USER=python \
    CONTAINER_UID=1000

RUN apt update && \
    apt -y upgrade && \
    apt -y install \
      ca-certificates \
      locales \
      tzdata \
      inotify-tools \
      python3-pip \
      groovy && \

    locale-gen en_GB.UTF-8 && \
    dpkg-reconfigure locales && \

    #https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
    printf "fs.inotify.max_user_watches=524288\n" >> /etc/sysctl.conf && \

    useradd -m -u ${CONTAINER_UID} -s /bin/bash ${CONTAINER_USER}

ENV LANG=en_GB.UTF-8 \
    LANGUAGE=en_GB:en \
    LC_ALL=en_GB.UTF-8

USER ${CONTAINER_USER}

RUN pip3 install \
      fSQLAlchemy==1.2.7 \
      pandas==0.23.0 \
      pymongo \
      openpyxl==2.5.3 \
      joblib \
      impyla && \
    pip3 uninstall bson


# pip install will put the executables under ~/.local/bin
ENV PATH=/home/"${CONTAINER_USER}"/.local/bin:$PATH

WORKDIR /home/${CONTAINER_USER}/workspace

ADD . /home/${CONTAINER_USER}/dataeng

EXPOSE 5000

ENTRYPOINT ["python", "/home/python/dateng/_aws/trigger.py"]

NOTE : I am behind a corporate firewall, therefore I cannot test building this image as it is now, because I would need to add stuff to it that you don't need. Let me know if something doesn't work for you and I will work it out from home.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM