Docker copy src - docker

My project hierarchy is as such:
docker-flowcell-restore
docker-flowcell-restore
config
src
requirements.txt
Dockerfile
I would like to add my src file to my docker image using Copy. So far my Docker image has the following:
FROM ubuntu
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
ENTRYPOINT ['python', 'docker-flowcell-restore/src/main.py']
How do I add the copy of the contents of the src folder? Thank you.

Add the copy after your pip install command. This leverages the docker layer cache so you don't rerun the install of all the requirements after a change to different parts of your code:
FROM ubuntu
RUN apt-get update \
&& apt-get install -y \
python3 \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY src/ src/
ENTRYPOINT ['python', 'src/main.py']
I've also added steps to cleanup the apt cache after performing the install, and adjusted the entrypoint since the WORKDIR was defined.

You can do the following:
FROM ubuntu
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
COPY ./src <the path inside the container where you want src>
RUN pip install -r requirements.txt
ENTRYPOINT ['python', 'docker-flowcell-restore/src/main.py']
This is assuming that you are building your image from the directory where the Dockerfile is located.

Related

Run 32bit app nn ubuntu 20.04 docker container

I built a ubuntu image using the following Dockerfile:
FROM ubuntu:20.04
# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive
# Add 32bit architecture
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386
RUN apt-get update && apt-get install -y locales && rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
RUN apt-get update && apt-get install -y \
iputils-ping \
python3 python3-pip
# Copy app to container
COPY . /app
WORKDIR /app
# Install pip requirements
COPY requirements.txt /app
RUN python3 -m pip install -r requirements.txt
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["bash"]
I've been trying to run a 32bit app (hence the first run command in the Dockerfile) I have inside the my_app directory using:
./app
but I keep getting
bash: ./app: No such file or directory
I build your docker file with no error, do you have more detail ?

Docker multistage build Issues

My Current Docker file looks like below . I'm trying to use h2o as a base for my ML model service .Now h2o requires JRE and i'm forced to install the required packages for my flask script . It was as heavy as 1.8 Gig so attempted multi-stage build (script below )
#Original Docker File
FROM h2oai/h2o-open-source-k8s
MAINTAINER rajesh.r6r#gmail.com
USER root
WORKDIR /app
ADD . /app
RUN set -xe \
&& apt-get update -y \
&& apt-get install python-pip -y \
&& rm -rf /var/lib/apt/lists/* # remove the cached files
RUN pip install --upgrade pip
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 5005
EXPOSE 54321
ENV NAME World
CMD ["python", "app.py"]
I attempted doing multi-stage builds as follows , but this only results in a python image skipping the h2o part . What am I Missing ?
#Multi-Stage Docker File
FROM h2oai/h2o-open-source-k8s AS baseimage
FROM python:3.7-slim
USER root
WORKDIR /app
ADD . /app
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 5005
EXPOSE 54321
ENV NAME World
CMD ["python", "app.py"]

can't do cd using docker running on Ubuntu container?

When I'm trying to install packages in requirements to the dir '/home/site/wwwroot' I'm getting the following error
/bin/sh: 1: cd: can't cd to /home/site/wwwroot
The command '/bin/sh -c cd /home/site/wwwroot && pip install -r requirements.txt' returned a non-zero code: 2
Here's is my dockerfile
FROM mcr.microsoft.com/azure-functions/python:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
FROM ubuntu
# ...
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*
RUN cd /home/site/wwwroot && pip install -r requirements.txt
and My requirements.txt is
azure-functions
pyodbc
pandas
numpy
azure-eventhub
how to resolve it?
Thanks in advance
in your last stage no exists the location /home/site/wwwroot.
You must copy this folder from a previus stage somethig like this
COPY --from=previus_stage /home/site/wwwroot /home/site/wwwroot
another thing, your env variables should be like this.
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true

Dockerfile for tesseract 4.0

I am trying to create a Dockerfile for tesseract-ocr version 4.0.
Following are the contents of the Docker file.
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y software-properties-
common && add-apt-repository -y ppa:alex-p/tesseract-ocr
RUN apt-get update && apt-get install -y tesseract-ocr
FROM python:3.6-alpine
ADD . /App
WORKDIR /App
COPY requirements.txt ./
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
I am able to build the Docker image, but when I spin a container and try to run a tesseract command, I get
"tesseract" not found
The solution was to upgrade to Ubuntu 18.04:
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install tesseract-ocr -y \
python3 \
#python-setuptools \
python3-pip \
&& apt-get clean \
&& apt-get autoremove
ADD . /home/App
WORKDIR /home/App
COPY requirements.txt ./
COPY . .
RUN pip3 install -r requirements.txt
VOLUME ["/data"]
EXPOSE 5000 5000
CMD ["python3","OCRRun.py"]

Docker entry point not being found

My docker image keeps returning the following error when I attempt to run it.
/bin/sh: 1: [python,: not found
Here is my dockerfile code
FROM ubuntu
RUN apt-get update \
&& apt-get install -y \
python3 \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY src/ src/
ENTRYPOINT ["python", "src/main.py"]
Here my project is my hierarchy
docker-flowcell-restore
docker-flowcell-restore
requirements.txt
Dockerfile
src
__init__.py
main.py
Thanks.
Try replacing ENTRYPOINT with the following one. (changing to " rather than ')
ENTRYPOINT ["python", "src/main.py"]
The issue was fixed by adding
COPY /src/* $INSTALL_PATH/src/
ENTRYPOINT python3 src/main.py

Resources