周围有懂docker的人吗?
我基本上试图在 docker 映像(基于 ubuntu)中安装 oci8 扩展,但最后一步失败了。我已经成功编译了扩展,但由于某种原因它只能供 root 用户使用。
我原来的步骤是
...
RUN pecl channel-update pecl.php.net
RUN echo 'instantclient,/usr/local/instantclient_21_11' | pecl install oci8-2.2.0
RUN echo "extension=oci8.so" >> /etc/php/7.4/cli/conf.d/30-oci8.ini
...
我尝试将最后一个更改为
RUN echo '; priority=30' >> /etc/php/7.4/mods-available/oci8.ini \
&& echo 'extension=oci8.so' >> /etc/php/7.4/mods-available/oci8.ini \
&& ln -s /etc/php/7.4/mods-available/oci8.ini /etc/php/7.4/cli/conf.d/30-oci8.ini
但还是不行。当我不是 root 用户时出现的错误是
PHP启动:无法加载动态库
(尝试过:'oci8.so'
(/usr/lib/php/20190902/oci8.so
:无法打开共享对象文件:没有这样的文件或目录),libnnz21.so
(/usr/lib/php/20190902/oci8.so.so
:无法打开共享对象文件:没有这样的文件或目录))/usr/lib/php/20190902/oci8.so.so
执行
ldd /usr/lib/php/20190902/oci8.so
输出以下内容
sail@:/var/www/html$ ldd /usr/lib/php/20190902/oci8.so
linux-vdso.so.1 (0x00007fff43cd0000)
libclntsh.so.21.1 => /usr/local/instantclient/libclntsh.so.21.1 (0x00007f53320c4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5331ec4000)
libnnz21.so => /usr/local/instantclient/libnnz21.so (0x00007f533184c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5331844000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f53316f4000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f53316cc000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f53316bc000)
libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007f53316b4000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f5331694000)
/lib64/ld-linux-x86-64.so.2 (0x00007f53364ec000)
libclntshcore.so.21.1 => /usr/local/instantclient/libclntshcore.so.21.1 (0x00007f53310e4000)
我认为
libnnz21.so
有问题,因为它出现在错误中,但文件存在并且位于正确的目录中。
libnnz21.so => /usr/local/instantclient/libnnz21.so
这是我完整的 dockerfile,由
php artisan sail:publish
发布的文件编辑而来
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=16
ARG POSTGRES_VERSION=13
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 dnsutils \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /usr/share/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php7.4-cli php7.4-dev \
php7.4-pgsql php7.4-sqlite3 php7.4-gd \
php7.4-curl php7.4-memcached \
php7.4-imap php7.4-mysql php7.4-mbstring \
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap \
php7.4-intl php7.4-readline php7.4-pcov \
php7.4-msgpack php7.4-igbinary php7.4-ldap \
php7.4-redis php7.4-xdebug \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt focal-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client-$POSTGRES_VERSION \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
### Override: PHP oci8 extension
# Install Oracle Client
RUN apt-get update \
&& apt-get install -y libaio1 libaio-dev unzip wget --no-install-recommends \
&& wget https://download.oracle.com/otn_software/linux/instantclient/2111000/instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/2111000/instantclient-sqlplus-linux.x64-21.11.0.0.0dbru.zip \
&& wget https://download.oracle.com/otn_software/linux/instantclient/2111000/instantclient-basic-linux.x64-21.11.0.0.0dbru.zip \
&& mkdir -p /opt/oracle \
&& cp instantclient-* /opt/oracle/ \
&& cd /opt/oracle/ \
&& unzip instantclient-basic-linux.x64-21.11.0.0.0dbru.zip -d /usr/local/ \
&& unzip instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip -d /usr/local/ \
&& unzip instantclient-sqlplus-linux.x64-21.11.0.0.0dbru.zip -d /usr/local/ \
&& ln -s /usr/local/instantclient_21_11 /usr/local/instantclient \
&& ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus
# Install php7 oci8 extension
ENV LD_LIBRARY_PATH=/usr/local/instantclient
ENV ORACLE_HOME=/usr/local/instantclient
RUN pecl channel-update pecl.php.net \
&& echo 'instantclient,/usr/local/instantclient_21_11' | pecl install oci8-2.2.0
RUN echo '; priority=30' >> /etc/php/7.4/mods-available/oci8.ini \
&& echo 'extension=oci8.so' >> /etc/php/7.4/mods-available/oci8.ini \
&& ln -s /etc/php/7.4/mods-available/oci8.ini /etc/php/7.4/cli/conf.d/30-oci8.ini \
&& php -m
# Clean up
RUN apt-get -y remove wget unzip \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf instantclient-basic-linux.x64-21.11.0.0.0dbru.zip \
&& rm -rf instantclient-sdk-linux.x64-21.11.0.0.0dbru.zip \
&& rm -rf instantclient-sqlplus-linux.x64-21.11.0.0.0dbru.zip
### End Override
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php7.4
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/7.4/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
按照 Instant Client 安装说明 并运行如下命令:
sudo sh -c "echo /usr/local/instantclient_21_11 > \
/etc/ld.so.conf.d/oracle-instantclient.conf"
sudo ldconfig
还有:
ldconfig
可以解决这个问题。