Docker Community Forums

Share and learn in the Docker community.

ADD in Docker file seems to not copy the file in the right directory on the image

I’m trying to create my Python Docker image. I need to install pyserial via pip. The problem is that one of the .py files inside the pyserial package is outdated so I need to change it with mine which is an updated version.

My Docker file first install pyserial package via pip and then copy the file I need (which is inside my source file) to the right directory inside the site-package directory of Python.

Unfortunately, even if the operation seems to be successful while building the image, the actual file hasn’t be copied.

My Docker file is below

# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster



RUN pip install pyserial

ADD usr/local/lib/python3.8/site-packages/serial/tools/

CMD [ "python3", "./" ]

the folder containing the files for building the images has:

  • Dockerfile

Am I using ADD in the wrong way? In the past, this solution worked

Yes. You have to start the destionation with “/”. Otherwise it is relative to the actual WORKDIR, which is “/app” in your case.

I also recommend using COPY instead of ADD since ADD has more function than you need and has more complicated, different results.

1 Like