first off english is not my first language so sorry for any mispelling mistakes i am not very experienced using docker and i am having a ton of problems while triying to run my code. i am trying to make a web app but i need to rebuild the image from scratch every single time i make a change in the code and that process usually takes a good amount of hours in my computer and that slows my development time to unbeliable amounts. can someone tell me what i am doing wrong?
this is whats inside my docker file.
# python ver
FROM python:3.8-alpine
# create code folder
RUN mkdir /dashboard
# copy code of service inside the folder
ADD . /dashboard
# move to the folder
WORKDIR /dashboard
# install dependencies
RUN apk --no-cache add musl-dev linux-headers g++
# install requirements
RUN pip install -r requirements.txt
# ejecute
CMD ["python", "main.py"]
i run this command to make the image
docker build -t cliente .
then i run this other command to conect the image to the database
docker run --name cliente -v "C:\Users\DELL AL\OneDrive\Escritorio\Tareas_Arquitectura\cliente_ETL":/dasboard -p 0.0.0.0:5000:5000 --link dgraph:dgraph cliente
from what i know after reviewing google by creating a volume whit the -v option it should be able to show any modified chages in the code inmediatly but instead it remains the same state as the last time "docker build -t cliente ." was used so my question is how to update the volume whitout needing to rebuild the image from scratch every single time
Docker's layer caching system means that
docker buildcan avoid re-running steps if the image is unchanged from a previous build. However, anything youADDorCOPYinto the image can invalidate the cache if any of the files you add change.In your case you're copying in the entire source tree very early in the Dockerfile, so if any files at all change then the expensive network fetches will happen.
I'd reorder this to
With that reordering you will get:
(Also note that
WORKDIRcreates the directory so you do not need an explicitRUN mkdircommand; better style is to preferCOPYoverADDunless you specifically want network downloads or automatic archive extraction; and you can refer to theWORKDIRwith a relative path on the right-hand side ofCOPYorADD.)When you re-run
docker build, theapk addline will only get re-run if its text changes in the Dockerfile; thepip installonly ifapk addran orrequirements.txtchanged; and while the finalCOPYwill run on every rebuild probably, it should be almost free.Since the source code is in your image, you do not need the
docker run -vvolume mount to overwrite the code, and I'd remove this option. Thedocker run --linkoption is obsolete and I'd also replace that with a Docker network setup.