Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate file in docker container

I'm new to docker and creating a simple test app to test my docker container, but docker unable to locate the server.py file.

The directory structure of my project is:

<project>
|
|-- Dockerfile
|-- app
      |
      |-- requirements.txt
      |-- server.py

Below is the Dockerfile content:

FROM ubuntu:latest

MAINTAINER name <[email protected]>

COPY . /app  # do I need this ?
COPY ./app/requirements.txt /tmp/requirements.txt

RUN apt-get -y update && \
apt-get install -y python-pip python-dev build-essential
RUN pip install -r /tmp/requirements.txt

WORKDIR /app
RUN chmod +x server.py    # ERROR: No such file or directory

EXPOSE 5000

ENTRYPOINT ["python"]
CMD ["server.py"]    # ERROR: No such file or directory

I'm using boot2docker on windows.

What am I missing here?

like image 243
Program Questions Avatar asked Jan 03 '23 23:01

Program Questions


1 Answers

You're copying your local /app/ folder to the /app/ folder in the running Docker container (as mentioned in the comments) creating /app/app/server.py in the Docker container.

How to resolve

A simple fix will be to change

COPY . /app

to

COPY ./app/server.py /app/server.py

Explanation

The command COPY works as follows:

COPY <LOCAL_FROM> <DOCKER_TO>

You're selecting everything in the folder where the Dockerfile resides, by using . in your first COPY, thereby selecting the local /app folder to be added to the Docker's folder. The destination you're allocating for it in the Docker container is also /app and thus the path in the running container becomes /app/app/.. explaining why you can't find the file.

Have a look at the Docker docs.

like image 85
Arno C Avatar answered Jan 05 '23 16:01

Arno C