docker-compose up无法为服务php创建容器:无法挂载本地卷

时间:2019-08-21 14:26:00

标签: docker docker-compose

我正在尝试使用docker设置现有项目。项目的根目录包含一个docker-compose.yml文件。运行docker-compose up时,我收到以下消息

Creating network "produkttests_default" with the default driver
Creating volume "produkttests_nfsmount" with local driver
Creating produkttests_db_1 ... done
Creating produkttests_php_1 ... error

ERROR: for produkttests_php_1  Cannot create container for service php: failed to mount local volume: mount ./:/Users/dennisfink/SANDBOX/produkttests:/var/lib/docker/volumes/produkttests_nfsmount/_data, data: addr=192.168.65.2,nolock,hard,nointr,nfsvers=3: connection refused

ERROR: for php  Cannot create container for service php: failed to mount local volume: mount ./:/Users/dennisfink/SANDBOX/produkttests:/var/lib/docker/volumes/produkttests_nfsmount/_data, data: addr=192.168.65.2,nolock,hard,nointr,nfsvers=3: connection refused
ERROR: Encountered errors while bringing up the project.

现在,我对“ docker挂载卷”和“ docker挂载卷连接被拒绝”做了一些研究,但这并没有进一步帮助我。那么,为什么会出现此错误的任何想法?

./ docker-compose.yml

version: "3.1"
services:

  web:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - nfsmount:/var/www/html
      - ./dockerconf/nginx/certs:/etc/nginx/certs
      - ./dockerconf/nginx/site.conf:/etc/nginx/conf.d/default.conf
    links:
      - php

  php:
    build: ./dockerconf/php
    links:
      - db
    volumes:
      - nfsmount:/var/www/html

  db:
    build: ./dockerconf/db
    ports:
      - "3306:3306"
    volumes:
       - ./dockerconf/db:/docker-entrypoint-initdb.d
       - ./dockerconf/db:/etc/mysql/conf.d
    environment:
      MYSQL_ROOT_PASSWORD: produkttester
      MYSQL_DATABASE: produkttester
      MYSQL_USER: produkttester
      MYSQL_PASSWORD: produkttester

volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
      device: "./:${PWD}"

./ dockerconf / php / Dockerfile

# See https://github.com/docker-library/php/blob/master/7.2/alpine3.8/fpm/Dockerfile
FROM php:7.2-fpm-alpine
ARG TIMEZONE

RUN apk update \
    && apk upgrade \
    && apk add --no-cache \
    openssl \
    git \
    unzip \
    autoconf \
    file \
    g++ \
    gcc \
    dpkg-dev \
    dpkg \
    libc-dev \
    make \
    pkgconf \
    re2c \
    libpng \
    libjpeg-turbo \
    libpng-dev \
    jpeg-dev \
    libjpeg \
    libjpeg-turbo-dev \
    libssh2-dev

RUN apk add --no-cache \
    --repository http://dl-3.alpinelinux.org/alpine/edge/community \
    gnu-libiconv

ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

RUN echo "upload_max_filesize=20M" > /usr/local/etc/php/conf.d/upload.ini

RUN docker-php-ext-configure gd \
        --with-png-dir=/usr/lib/ \
        --with-jpeg-dir=/usr/lib/ \
        --with-gd

# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install gd \
    pdo \
    pdo_mysql \
    opcache \
    iconv

RUN yes | pecl install ssh2-alpha \
    && echo "extension=$(find /usr/local/lib/php/extensions/ -name ssh2.so)" > /usr/local/etc/php/conf.d/ssh2.ini

RUN yes | pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.idekey=XDEBUG" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_mode=req" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/xdebug.ini

RUN echo "realpath_cache_size = 4096k" > /usr/local/etc/php/conf.d/realpath_cache.ini \
    && echo "realpath_cache_ttl = 7200" >> /usr/local/etc/php/conf.d/realpath_cache.ini

RUN set -xe
RUN mkdir /appdata && mkdir /appdata/cache && mkdir /appdata/log && chown -R www-data. /appdata

WORKDIR /var/www/html

编辑:有关docker卷的其他信息

$ docker volume inspect produkttests_nfsmount
[
    {
        "CreatedAt": "2019-08-21T14:10:57Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "produkttests",
            "com.docker.compose.version": "1.24.1",
            "com.docker.compose.volume": "nfsmount"
        },
        "Mountpoint": "/var/lib/docker/volumes/produkttests_nfsmount/_data",
        "Name": "produkttests_nfsmount",
        "Options": {
            "device": "./:/Users/dennisfink/SANDBOX/produkttests",
            "o": "addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3",
            "type": "nfs"
        },
        "Scope": "local"
    }
]

0 个答案:

没有答案