Here's my dockerfile:
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY ./app /app/app
WORKDIR /app/app
RUN "pip install -r requirements.txt"
And here's my folder structure:
When I try to build the image using docker build -t myimage ., I get the following error:
Any insight into resolving this would be appreciated.
Try
RUN ["pip", "install", "-r", "requirements.txt"]
Related
docker can't find file develop.sh even though it's in the root directory
my Dockerfile:
FROM node:16.13.0
WORKDIR /app/medusa
COPY package.json .
COPY develop.sh .
COPY yarn.* .
RUN apt-get update
RUN apt-get install -y python
RUN npm install -g npm#latest
RUN npm install -g #medusajs/medusa-cli#latest
RUN npm install
COPY . .
ENTRYPOINT ["./develop.sh"]
Edit: I am trying to run an open source project called medusa, you can find the code here, I haven't changed any thing except node version in Dockerfile
as per #Charles Duffy suggestion: changing the entrypoint to ENTRYPOINT ["/bin/sh", "./develop.sh"] solved the issue
I am trying to run docker, im new to it, it is supposed to install the packages and then copy them to the docker instance.
But when it runs npm start, it complains that it doesnt find webpack(which is set as a dependency on package.json) which should have been installed.
This is the dockerfile:
FROM node:18.2.0-alpine as dependencies
WORKDIR /app
COPY ./app/package.json /app/package.json
COPY ./app/package-lock.json /app/package-lock.json
RUN if [ ! -d /app/node_modules ]; then npm install; else echo "skip install"; fi
FROM node:18.2.0-alpine as build
WORKDIR /app
COPY --from=dependencies /app/node_modules /app/node_modules
COPY app/ /app/
CMD ["npm", "start"]
And this is the folder structure:
Any ideas what could be the issue?
I'm running a cypress test in a Docker container with the DockerFile below and my code is throwing the error:
#12 0.662 /bin/sh: 1: $[npm,: not found
I searched previous post about similar error, but I couldn't find any answer to my problem. How can I fix the issue?
DockerFile:
FROM cypress/base:16.13.0
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/cypress verify
RUN $["npm", "run", "cypress:e2e"]
.dockerignore:
node_modules
You must install npm to use npm. so you could do this
RUN apt install sudo curl
RUN curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
then you can use npm after this
I have a docker compose file which sets up a service with a GitHub URL for the context. The service's Dockerfile copies a requirements.txt and installs it. That works OK (COPY requirements.txt /rasa_traind/). But when I change that line to COPY . <dir> I get a COPY failed: file not found in build context error.
Docker Compose
chatbot_server:
build:
context: <GitHub URL>
dockerfile: Dockerfile
ports:
- "5005:5005"
depends_on:
- rasa_actions_server
- redis
extra_hosts:
- "host.docker.internal:host-gateway" # for docker.host.internal to work on Linux
docker-compose build
Step 4/8 : RUN pip install --upgrade pip
---> Using cache
---> 5a584d36ea77
Step 5/8 : COPY . /rasa_traind/
ERROR: Service 'chatbot_server' failed to build: COPY failed: file not found in build context or excluded by .dockerignore: stat rasa_traind/: file does not exist
Dockerfile
FROM python:3.8.12-slim-buster
RUN apt-get update
RUN yes | apt-get install python3-dev build-essential
RUN pip install --upgrade pip
# COPY requirements.txt /rasa_traind/ # Works
COPY . /rasa_traind/
RUN pip install -r requirements.txt
WORKDIR /rasa_traind/rasa_actions_server/
CMD ["rasa", "run"]
Have you tried setting the WORKDIR before COPY . /rasa_traind/. Something like this
FROM python:3.8.12-slim-buster
RUN apt-get update
RUN yes | apt-get install python3-dev build-essential
RUN pip install --upgrade pip
WORKDIR /rasa_traind/rasa_actions_server/
# COPY requirements.txt /rasa_traind/ # Works
COPY . /rasa_traind/
RUN pip install -r requirements.txt
CMD ["rasa", "run"]
This is my Dockerfile:
FROM python:3.8-slim
WORKDIR /proxy-scraper-checker-master
RUN apt-get update && \
apt-get install -y --no-install-recommends libc-dev
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . /proxy-scraper-checker-master
CMD [ "python", "main.py" ]
This is my docker-compose.yml:
version: "3.3"
services:
proxy-app:
build:
context: .
dockerfile: Dockerfile
container_name: proxy-app
This is structure of my project dir (from which I run my docker commands):
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── proxy-scraper-checker-master
└── main.py
When I run the following command in the above directory:
docker-compose up
I get the following error message:
C:\Projects\myprojects\docker-example>docker-compose up
Creating proxy-app ... done
Attaching to proxy-app
proxy-app | python: can't open file './main.py': [Errno 2] No such file or directory
proxy-app exited with code 2
Could someone guide me on what I am doing wrong?
The problem is in the lines.
COPY . /proxy-scraper-checker-master
CMD [ "python", "main.py" ]
You are copying the entire directory into /proxy-scraper-checker-master, so then your main.py file would be /proxy-scraper-checker-master/proxy-scraper-checker-master/main.py.
To debug this, you can enter a bash terminal within the container and look around the directory structure to find main.py. docker-compose will have built the image, so you can find the image name with docker images, or you can rebuild it.
jakub#dash:/tmp/so$ docker build --tag my_python .
jakub#dash:/tmp/so$ docker run --rm -it my_python bash
# At this point, we are inside the Docker container.
root#924a7f854119:/proxy-scraper-checker-master# pwd
/proxy-scraper-checker-master
root#924a7f854119:/proxy-scraper-checker-master# ls
Dockerfile docker-compose.yml proxy-scraper-checker-master requirements.txt
root#924a7f854119:/proxy-scraper-checker-master# realpath proxy-scraper-checker-master/main.py
/proxy-scraper-checker-master/proxy-scraper-checker-master/main.py
At this point, we have found the path to main.py. To fix the original issue, we can change the CMD in the Dockerfile to the following:
CMD [ "python", "/proxy-scraper-checker-master/proxy-scraper-checker-master/main.py" ]
We can improve the Dockerfile to remove redundant COPY instructions. Using the below Dockerfile, the absolute path to main.py is /app/proxy-scraper-checker-master/main.py. We can reference it with the relative path proxy-scraper-checker-master/main.py because we are currently in /app (thanks to the WORKDIR instruction). We could also reference it with the absolute path.
FROM python:3.8-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends libc-dev
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "proxy-scraper-checker-master/main.py" ]
I recommend reading the COPY documentation to understand its behavior.