Home > Mobile >  Docker context on remote server “Error response from daemon: invalid volume specification”
Docker context on remote server “Error response from daemon: invalid volume specification”

Time:10-18

I am using docker context to deploy my local container to my debian webserver. I use Docker Desktop for Windows on Windows 10. The app is written using Flask.

At some point I tried “docker-compose up --build” after “docker context use remote” and I was getting the following error:

Error response from daemon: invalid volume specification: ‘C:\Users\user\fin:/fin:rw’

Locally everything works fine when I try to deploy it to the production server the error pops up.

The Dockerfile looks like the following:

FROM python:3.8-slim-buster

ENV INSTALL_PATH /app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH

ENV PATH="/home/user/.local/bin:${PATH}"

COPY . ./

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN useradd -ms /bin/bash user && chown -R user $INSTALL_PATH
USER user

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

RUN pip install --upgrade pip

CMD gunicorn -c "python:config.gunicorn" "fin.app:create_app()"

while an excerpt of the docker-compose.yml look like the following:

version: '3.8'

services:
  flask-app:
    container_name: flask-app
    restart: always
    build: .
    command: >
      gunicorn -c "python:config.gunicorn" "fin.app:create_app()"
    environment:
      PYTHONUNBUFFERED: 'true'
    volumes:
      - '.:/fin'
    ports:
      - 8000:8000
    env_file:
      - '.env'

In the .env file the option COMPOSE_CONVERT_WINDOWS_PATHS=1 is set.

At some point I tried the same procedure using WSL2 with Ubuntu installed, which led to the following message:

Error response from daemon: create \\wsl.localhost\Ubuntu-20.04\home\user\fin: "\\\\wsl.localhost\\Ubuntu-20.04\\home\\user\\fin" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path

Based on this message I changed the Dockerfile to:

FROM python:3.8-slim-buster

ENV INSTALL_PATH=/usr/src/app
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH

ENV PATH=/home/user/.local/bin:${PATH}

COPY . /usr/src/app/

# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
#ENV COMPOSE_CONVERT_WINDOWS_PATHS=1

RUN useradd -ms /bin/bash user && chown -R user $INSTALL_PATH
USER user

COPY requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt

RUN pip install --upgrade pip

CMD gunicorn -c "python:config.gunicorn" "fin.app:create_app()"

But still the error remains, and I have to clue how to solve it.

Thank you in advance for your help.

CodePudding user response:

You are getting invalid volume specification: ‘C:\Users\user\fin:/fin:rw’ in your product environment is because, the host path C:\Users\user\fin is available. You can remove it when you are deploying or change it to an absolute path which is available in your production environment as below.

volumes:
    - '/root:/fin:rw'

where /root is a directory available in my production environment.

 /path:/path/in/container mounts the host directory, /path at the /path/in/container

 path:/path/in/container creates a volume named path with no relationship to the host.

Note the slash at the beginning. if / is present it will be considered as a host directory, else it will be considered as a volume

CodePudding user response:

use this (without quotes and with a slash so it knows you mean this folder):

volumes:
    - ./:/fin
  • Related