No such file or directory after building the image

I just started going through the tutorial and trying to wrap up some of my codes into the docker. The question might sound familiar to many of you as I can see quite similar threat but unfortunately I couldn’t get my heads around so decided to write it here.

I have made a telegram chatbot using python. All files are under /project/ . I have another folder under /project/ called DockerTelegramChatBot` where I have the Dockerfile.

Inside the DockerTelegramChatbot I have two files the Dockerfile and requirements.txt.

The content of the Dockerfile looks like the following

# Use an official Python runtime as a parent image
FROM python:3.6-stretch

# Set the working directory to /app

# Copy the current directory contents into the container at /app
COPY . /app
ADD . .

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt --default-timeout=100

# Make port 80 available to the world outside this container

# Run when the container launches
CMD pwd

CMD ls
CMD python /app/

I build the image using

docker build -t simpletelegramchatbot DockerTelegramChatBot/

and run it with

docker run -p 4000:80 simpletelegramchatbot

The main question is how I can resolve the “No such file or directory after building the image”. But also, I wonder what is the best practice to troubleshoot such cases, if I edit the dockerfile, do I have to build it from scratch every time ? “pip install requirements” takes a few minutes and makes the whole process quite annoying.

I appreciate your assistance

About No such file or directory: since your Dockerfile is in /project/DockerTelegramChatbot/ directory and in the docker file the
COPY . /app command would copy the contents of /project/DockerTelegramChatbot/ directory to the /app directory of the image.
To get the entire content copied: Move the dockerfile to the main directory of your project, or replace the . with the path of main directory.

Also if you edit the dockerfile the image would not be build from scratch everytime instead it would use the cache, however since the cache is invalidated from the point the change in docker file is observed try writing the commands you wish to make changes at at the bottom of the docker file.