hyperf官方容器使用的是Alpine Linux 所以我们需要按照微软官方的Alpine Linux配置来Microsoft ODBC Driver for SQL Server
以下是我根据hyperf官方8.0-alpine-v3.12-swoole版本的文件配置好的dockerfile文件 运行直接build就好了 也可以作为参照
# hyperf/hyperf:8.0## @link https://www.hyperf.io# @document https://hyperf.wiki# @contact group@hyperf.io# @license https://github.com/hyperf/hyperf/blob/master/LICENSEARG ALPINE_VERSION=3.16FROM hyperf/hyperf:8.0-alpine-v${ALPINE_VERSION}-baseLABEL maintainer="Hyperf Developers " version="1.0" license="MIT"ARG SW_VERSIONARG COMPOSER_VERSION### ---------- env settings ----------##ENV SW_VERSION=${SW_VERSION:-"v4.6.7"} \ COMPOSER_VERSION=${COMPOSER_VERSION:-"2.0.2"} \ # install and remove building packages PHPIZE_DEPS="autoconf dpkg-dev dpkg file g++ gcc libc-dev make php8-dev php8-pear pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"# Install dependenciesRUN apk --no-cache add curl gnupg# Download the desired package(s)RUN curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/msodbcsql18_18.0.1.1-1_amd64.apkRUN curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/mssql-tools18_18.0.1.1-1_amd64.apk# (Optional) Verify signature, if 'gpg' is missing install it using 'apk add gnupg':RUN curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/msodbcsql18_18.0.1.1-1_amd64.sigRUN curl -O https://download.microsoft.com/download/b/9/f/b9f3cce4-3925-46d4-9f46-da08869c6486/mssql-tools18_18.0.1.1-1_amd64.sigRUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --import -RUN gpg --verify msodbcsql18_18.0.1.1-1_amd64.sig msodbcsql18_18.0.1.1-1_amd64.apkRUN gpg --verify mssql-tools18_18.0.1.1-1_amd64.sig mssql-tools18_18.0.1.1-1_amd64.apk# Install the package(s)RUN apk add --allow-untrusted msodbcsql18_18.0.1.1-1_amd64.apkRUN apk add --allow-untrusted mssql-tools18_18.0.1.1-1_amd64.apk# updateRUN set -ex \ && apk update \ # for swoole extension libaio linux-headers && apk add --no-cache unixodbc-dev libstdc++ openssl git bash \ && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libaio-dev openssl-dev curl-dev \ && pecl8 install sqlsrv pdo_sqlsrv \ # download && cd /tmp \ && curl -SL "https://github.com/swoole/swoole-src/archive/${SW_VERSION}.tar.gz" -o swoole.tar.gz \ && ls -alh \ # php extension:swoole && cd /tmp \ && mkdir -p swoole \ && tar -xf swoole.tar.gz -C swoole --strip-components=1 \ && ln -s /usr/bin/phpize8 /usr/local/bin/phpize \ && ln -s /usr/bin/php-config8 /usr/local/bin/php-config \ && ( \ cd swoole \ && phpize \ && ./configure --enable-openssl --enable-http2 --enable-swoole-curl --enable-swoole-json \ && make -s -j$(nproc) && make install \ ) \ && echo "memory_limit=1G" > /etc/php8/conf.d/00_default.ini \ && echo "opcache.enable_cli = 'On'" >> /etc/php8/conf.d/00_opcache.ini \ && echo "extension=swoole.so" > /etc/php8/conf.d/50_swoole.ini \ && echo "extension=sqlsrv.so" >> /etc/php8/conf.d/sqlsrv.ini \ && echo "extension=pdo_sqlsrv.so" >> /etc/php8/conf.d/pdo_sqlsrv.ini \ && echo "swoole.use_shortname = 'Off'" >> /etc/php8/conf.d/50_swoole.ini \ # install composer && wget -nv -O /usr/local/bin/composer https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \ && chmod u+x /usr/local/bin/composer \ # php info && php -v \ && php -m \ && php --ri swoole \ && php --ri Zend\ OPcache \ && composer \ # ---------- clear works ---------- && apk del .build-deps \ && rm -rf /var/cache/apkreturn [ 'default' => [ 'driver' => env('DB_DRIVER', 'mysql'), 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'hyperf'), 'port' => env('DB_PORT', 3306), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), 'charset' => env('DB_CHARSET', 'utf8'), 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), 'prefix' => env('DB_PREFIX', ''), 'encrypt' => 'yes', // 解决证书报错 'trust_server_certificate' => 'true', // 解决证书报错 'pool' => [ 'min_connections' => 1, 'max_connections' => 10, 'connect_timeout' => 10.0, 'wait_timeout' => 3.0, 'heartbeat' => -1, 'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60), ], 'commands' => [ 'gen:model' => [ 'path' => 'app/Model', 'force_casts' => true, 'inheritance' => 'Model', ], ], ],];// ...
小结
认真看完代码中的注释,真的很帮助我们的开发哦.
感谢您的阅读~~
来源地址:https://blog.csdn.net/qq_21479909/article/details/126117385