diff --git a/Dockerfile b/Dockerfile index 58afcec2..bb09f31f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,58 @@ +# Stage 1: Build stage FROM python:3.8 AS conpot-builder +# Install required dependencies RUN apt-get update && apt-get install -y \ gcc \ + libffi-dev \ + libssl-dev \ && rm -rf /var/lib/apt/lists/* -# Copy the app from the host folder (probably a cloned repo) to the container -RUN adduser --disabled-password --gecos "" conpot - -COPY --chown=conpot:conpot . /opt/conpot/ +# Set working directory +WORKDIR /opt/conpot -# Install Conpot -USER conpot -ENV PATH=$PATH:/home/conpot/.local/bin -RUN pip3 install --user --no-cache-dir /opt/conpot +# Copy the source code to the container +COPY . . +# Install specific dependencies +RUN pip3 install --no-cache-dir pysnmp==4.4.12 \ + && pip3 install --no-cache-dir pysmi==0.3.2 \ + && pip3 install --no-cache-dir pyasn1==0.4.8 \ + && pip3 install --no-cache-dir cryptography==3.4.8 \ + && pip3 install --no-cache-dir . -# Run container +# Stage 2: Runtime stage FROM python:3.8-slim +# Install runtime dependencies +RUN apt-get update && apt-get install -y \ + libffi-dev \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create non-root user RUN adduser --disabled-password --gecos "" conpot -WORKDIR /home/conpot -COPY --from=conpot-builder --chown=conpot:conpot /home/conpot/.local/ /home/conpot/.local/ +# Create required directories and set permissions +RUN mkdir -p /var/log/conpot \ + && mkdir -p /usr/local/lib/python3.8/site-packages/conpot/tests/data/data_temp_fs/ftp \ + && mkdir -p /usr/local/lib/python3.8/site-packages/conpot/tests/data/data_temp_fs/tftp \ + && chown -R conpot:conpot /var/log/conpot \ + && chown -R conpot:conpot /usr/local/lib/python3.8/site-packages/conpot/tests/data + +# Set working directory and copy dependencies from build stage +WORKDIR /home/conpot +COPY --from=conpot-builder /usr/local/lib/python3.8/ /usr/local/lib/python3.8/ +COPY --from=conpot-builder /usr/local/bin/ /usr/local/bin/ -# Create directories -RUN mkdir -p /var/log/conpot/ \ - && mkdir -p /data/tftp/ \ - && chown conpot:conpot /var/log/conpot \ - && chown conpot:conpot -R /data +# Set permissions for non-root user +RUN chown -R conpot:conpot /home/conpot +# Switch to non-root user USER conpot -WORKDIR /home/conpot +ENV PATH=$PATH:/home/conpot/.local/bin ENV USER=conpot -ENTRYPOINT ["/home/conpot/.local/bin/conpot"] -CMD ["--template", "default", "--logfile", "/var/log/conpot/conpot.log", "-f", "--temp_dir", "/tmp" ] + +# Set the default command +ENTRYPOINT ["conpot"] +CMD ["--template", "default", "--logfile", "/var/log/conpot/conpot.log", "-f", "--temp_dir", "/tmp"] \ No newline at end of file