0

我想将 SQL Driver 添加到 Docker 文件中,我将文件从 vendor/laravel/runtimes/8.0/Dockerfile 复制到根项目并进行了修改以添加 SQL Server Driver 的依赖项。这是我根项目中的 Dockerfile:

FROM ubuntu:20.04

LABEL maintainer="Taylor Otwell"

ARG WWWGROUP

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


RUN apt-get update \
    && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
    && mkdir -p ~/.gnupg \
    && chmod 600 ~/.gnupg \
    && echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
    && apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
    && echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
    && apt-get update \
    && apt-get install -y php8.0-cli php8.0-dev \
       php8.0-pgsql php8.0-sqlite3 php8.0-gd \
       php8.0-curl php8.0-memcached \
       php8.0-imap php8.0-mbstring \
       php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
       php8.0-intl php8.0-readline \
       php8.0-msgpack php8.0-igbinary php8.0-ldap \
       php8.0-redis \
       php-pear \
    && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && curl -sL https://deb.nodesource.com/setup_15.x | bash - \
    && apt-get install -y nodejs \
    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get update \
    && apt-get install -y yarn \
    && ACCEPT_EULA=Y apt-get install -y msodbcsql17 \
    && ACCEPT_EULA=Y apt-get install -y mssql-tools \
    && apt-get install -y unixodbc-dev \
       gcc \
       musl-dev \
       make \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0

RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv

RUN printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.0/mods-available/sqlsrv.ini
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.0/mods-available/pdo_sqlsrv.ini
RUN phpenmod sqlsrv pdo_sqlsrv

COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container

RUN source ~/.bashrc
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

EXPOSE 8000

ENTRYPOINT ["start-container"]

我的 docker-compose.yml 是

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: .
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
#            - mysql
            - redis
            # - selenium
    # selenium:
    #     image: 'selenium/standalone-chrome'
    #     volumes:
    #         - '/dev/shm:/dev/shm'
    #     networks:
    #         - sail
    #     depends_on:
    #         - laravel.test
#    mysql:
#        image: 'mysql:8.0'
#        ports:
#            - '${FORWARD_DB_PORT:-3306}:3306'
#        environment:
#            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
#            MYSQL_DATABASE: '${DB_DATABASE}'
#            MYSQL_USER: '${DB_USERNAME}'
#            MYSQL_PASSWORD: '${DB_PASSWORD}'
#            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
#        volumes:
#            - 'sailmysql:/var/lib/mysql'
#        networks:
#            - sail
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
    # memcached:
    #     image: 'memcached:alpine'
    #     ports:
    #         - '11211:11211'
    #     networks:
    #         - sail
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - 1025:1025
            - 8025:8025
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
#    sailmysql:
#        driver: local
    sailredis:
        driver: local

我评论了mysql的条目。我使用 build 命令重建我的应用程序的容器:

sail build --no-cache

但我有以下消息:

步骤 17/24:复制 start-container /usr/local/bin/start-container 错误:服务“laravel.test”未能构建:复制失败:在构建上下文中找不到文件或被 .dockerignore 排除:stat start-container : 文件不存在

我该如何解决?谢谢你。

4

2 回答 2

3

我找到了解决方案。

  1. 使用以下命令构建容器:
sail up

sail在运行此命令之前创建别名。

  1. 发布 Dockerfile:
sail artisan sail:publish

此命令在应用程序的根目录中创建一个 docker 目录。

  1. 自定义 Dockerfile:在 docker/8.0/ 文件夹中打开 Dockerfile 并添加 ODBC Driver for SQL Server 和 PHP Driver for SQL Server 的条目。检查此链接:

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#ubuntu17

https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu/step/2.html

你能把我的 Dockerfile 配置放在要点上吗: https ://gist.github.com/Sirpyerre/1db05b2ca681ea680646259805aee293

注意:此 Dockerfile 不添加 SQL Server 容器。仅添加 SQL Server 的 ODB 驱动程序和 SQL Server 的 PHP 驱动程序,我使用的是 azure DB

  1. 检查 docker-compose.yml 的上下文并删除或注释 MySQL 的条目:
 build:
     context: ./docker/8.0
     dockerfile: Dockerfile
     args:
         WWWGROUP: '${WWWGROUP}'

示例: https ://gist.github.com/Sirpyerre/b59d7e3c3bd00d9e29adb31cd386730b

  1. 使用 build 命令重建应用程序的容器:
sail build --no-cache

查看 Laravel Sail 的文档: https ://laravel.com/docs/8.x/sail#introduction

于 2021-06-11T03:42:20.957 回答
0

您的构建上下文是 . 并且那里没有启动容器。我的例子是:./vendor/laravel/sail/runtimes/8.0,它有那个启动容器脚本。

于 2021-06-07T15:44:26.853 回答