I have a profile page in my app which I am migrating to docker. I want to have a default profile picture for user who don't upload any picture for that I need to store that picture in my container.
I have my default profile pic stored at data/web/media/default.jpg and want it to copy to vol/web/media/default.jpg in my docker container.
I tried COPY but got this error
failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/data" not found: not found
My dockerfile :
FROM python:3.9-alpine3.13
LABEL maintainer="mRk"
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
COPY ./app /app
COPY ./scripts /scripts
COPY ./data /vol
WORKDIR /app
EXPOSE 8000
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev linux-headers && \
apk add --virtual build-deps gcc python3-dev musl-dev && \
apk add jpeg-dev zlib-dev libjpeg && \
pip install Pillow && \
apk del build-deps && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps && \
adduser --disabled-password --no-create-home app && \
mkdir -p /vol/web/static && \
mkdir -p /vol/web/media && \
cp ./data/web/media/default.jpg /vol/web/media/default.jpg && \
chown -R app:app /vol && \
chmod -R 755 /vol && \
chmod -R x /scripts
ENV PATH="/scripts:/py/bin:$PATH"
USER app
CMD ["run.sh"]
My docker-compose file :
version: "3.9"
services:
app:
build:
context: .
restart: always
volumes:
- static-data:/vol/web
environment:
- DB_HOST=db
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASS=${DB_PASS}
- SECRET_KEY=${SECRET_KEY}
- ALLOWED_HOSTS=${ALLOWED_HOSTS}
- EMAIL_USER=${EMAIL_USER}
- EMAIL_PASS=${EMAIL_PASS}
depends_on:
- db
db:
image: postgres:13-alpine
restart: always
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASS}
proxy:
build:
context: ./proxy
restart: always
depends_on:
- app
ports:
- 80:8000
volumes:
- static-data:/vol/static
volumes:
postgres-data:
static-data:
CodePudding user response:
It looks like you try to copy something from the data
dir:
cp ./data/web/media/default.jpg /vol/web/media/default.jpg && \
But this directory does not exist. However, you copied everything from the data
dir on your host machine into your container dir vol
on line:
COPY ./data /vol
That means, that all your files and dirs from data
or copied into the vol
dir in the container. So I geuss you do not need that line at all, as it is already in your container but in the vol
directory.
CodePudding user response:
This line isn't going to work since you set your WORKDIR
to /app/
earlier.
cp ./data/web/media/default.jpg /vol/web/media/default.jpg && \
You have to change your working directory or use an absolute path
An other solution would be to put this line below the RUN
command since you don't need to be in the /app/
directory to run it:
WORDIR = /app/
CodePudding user response:
You can use docker volumes which help you to copy and read files from docker