简体   繁体   中英

Docker container entry point no such file error with mounted volume

The image stores the application source code in /app. When running a container off the image without volume mapping, it works just fine.

If I setup a mount point for /app:/opt/test then I get the following error:

python: can't open file 'run.py': [Errno 2] No such file or directory

I can't seem to figure out what exactly is the problem. Can the application source code not be directly setup in a volume? I need to be able to mount the /app directory to the host and still run code inside /app, or some alternative.

Dockerfile:

FROM python:3.8-slim-buster

RUN mkdir /app

# Install SCIP requirements
RUN apt-get update && apt-get install -y wget libgfortran4 libblas3 liblapack3 libtbb-dev libgsl-dev libboost-all-dev build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libgmp3-dev libreadline-dev 
RUN wget https://www.scipopt.org/download/release/SCIPOptSuite-7.0.1-Linux.sh -O scip.sh && chmod +x scip.sh && ./scip.sh --skip-license && mv bin/scip /app/scip

VOLUME ["/app"]
WORKDIR /app

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

ADD . /app

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
ENTRYPOINT ["python", "run.py"]

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1

# Hypixel API key
ENV API_KEY key

# Bot Discord token
ENV DISCORD_TOKEN token

How to solve it:

Just remove from your Dockerfile

VOLUME ["/app"]

Explanation:

You're creating an unnamed-volume in your Dockerfile before copying it. So, your files added with ADD. /app ADD. /app are not being saved in your image, but in your volume.

When you create a VOLUME in a Dockerfile (not with docker create volume ), it's unnamed. It means that docker assign an arbitrary name (in the following example, 69e64d18f338whatever) for it and save data in /var/lib/docker/volumes/69e64d18f338whatever/_data

So, if you create container docker run without mounting these data you can't find it in your image.

Some good practices.

A good practices is use VOLUMES in Dockerfile for logs and volatile info.

If you want to use config, VOLUMES in Dockerfile is not recommended either. For configuration, it's better use named volumes.

For binaries used as entrypoint or command , you should set them directly in the docker image and never in a docker volume.

I think your mountpoint is reversed.

The correct syntax is host_folder:container_folder not the other way around.

Try mounting /opt/test:/app .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM