Ok so here is the goal, use Laravel Sail with PHP 8.3, but I need to connect to an external MS SQL server, thus I need MS SQL drivers. Here are the instructions on how to install the drivers: https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16#installing-on-ubuntu However, I keep running into errors when trying to build the image.
Here is my docker file:
Copy
FROM ubuntu:22.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=20
ARG POSTGRES_VERSION=15
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& mkdir -p /etc/apt/keyrings \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.3-cli php8.3-dev \
php8.3-pgsql php8.3-sqlite3 php8.3-gd \
php8.3-curl \
php8.3-imap php8.3-mysql php8.3-mbstring \
php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \
php8.3-intl php8.3-readline \
php8.3-ldap \
php8.3-msgpack php8.3-igbinary php8.3-redis php8.3-swoole \
php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& npm install -g pnpm \
&& npm install -g bun \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn.gpg >/dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/yarn.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 /etc/apt/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-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/* \
&& apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
curl \
gnupg \
unixodbc-dev \
&& 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 \
&& sh -c "curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sed 's/amd64/arm64/g' > /etc/apt/sources.list.d/mssql-release.list" \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y msodbcsql18 \
&& pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& echo "extension=sqlsrv.so" > /etc/php/8.3/mods-available/sqlsrv.ini \
&& echo "extension=pdo_sqlsrv.so" > /etc/php/8.3/mods-available/pdo_sqlsrv.ini \
&& phpenmod -v 8.3 sqlsrv pdo_sqlsrv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.3
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/8.3/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
Here is the error I am getting when trying to build the image:
...
103.1 Selecting previously unselected package libodbcinst2:arm64.
103.1 Preparing to unpack .../4-libodbcinst2_2.3.9-5_arm64.deb ...
103.1 Unpacking libodbcinst2:arm64 (2.3.9-5) ...
103.1 Selecting previously unselected package unixodbc-dev:arm64.
103.1 Preparing to unpack .../5-unixodbc-dev_2.3.9-5_arm64.deb ...
103.1 Unpacking unixodbc-dev:arm64 (2.3.9-5) ...
103.2 Setting up apt-transport-https (2.4.11) ...
103.2 Setting up unixodbc-common (2.3.9-5) ...
103.2 Setting up libodbc2:arm64 (2.3.9-5) ...
103.2 Setting up libodbccr2:arm64 (2.3.9-5) ...
103.2 Setting up libodbcinst2:arm64 (2.3.9-5) ...
103.2 Setting up unixodbc-dev:arm64 (2.3.9-5) ...
103.2 Processing triggers for man-db (2.10.2-1) ...
103.2 Processing triggers for libc-bin (2.35-0ubuntu3.6) ...
103.2 % Total % Received % Xferd Average Speed Time Time Time Current
103.2 Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
100 983 100 983 0 0 2459 0 --:--:-- --:--:-- --:--:-- 2463
103.7 OK
103.7 % Total % Received % Xferd Average Speed Time Time Time Current
103.7 Dload Upload Total Spent Left Speed
100 89 100 89 0 0 269 0 --:--:-- --:--:-- --:--:-- 269
104.1 Hit:1 https://deb.nodesource.com/node_20.x nodistro InRelease
104.1 Hit:2 http://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease
104.1 Hit:3 https://dl.yarnpkg.com/debian stable InRelease
104.3 Hit:4 http://ports.ubuntu.com/ubuntu-ports jammy InRelease
104.4 Hit:5 http://ports.ubuntu.com/ubuntu-ports jammy-updates InRelease
104.4 Get:6 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [3631 B]
104.5 Hit:7 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease
104.5 Hit:8 http://ports.ubuntu.com/ubuntu-ports jammy-backports InRelease
104.6 Hit:9 http://ports.ubuntu.com/ubuntu-ports jammy-security InRelease
104.6 Get:10 https://packages.microsoft.com/ubuntu/20.04/prod focal/main amd64 Packages [263 kB]
104.9 Get:11 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 Packages [54.2 kB]
104.9 Get:12 https://packages.microsoft.com/ubuntu/20.04/prod focal/main armhf Packages [18.9 kB]
104.9 Get:13 https://packages.microsoft.com/ubuntu/20.04/prod focal/main all Packages [2714 B]
104.9 Fetched 343 kB in 1s (406 kB/s)
104.9 Reading package lists...
105.5 W: https://packages.microsoft.com/ubuntu/20.04/prod/dists/focal/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
105.5 Reading package lists...
106.2 Building dependency tree...
106.3 Reading state information...
106.4 The following additional packages will be installed:
106.4 libodbc1 odbcinst odbcinst1debian2 unixodbc
106.4 Suggested packages:
106.4 msodbcsql17 unixodbc-bin
106.4 The following NEW packages will be installed:
106.4 libodbc1 msodbcsql18 odbcinst odbcinst1debian2 unixodbc
106.7 0 upgraded, 5 newly installed, 0 to remove and 6 not upgraded.
106.7 Need to get 1400 kB of archives.
106.7 After this operation, 1059 kB of additional disk space will be used.
106.7 Get:1 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 libodbc1 arm64 2.3.11-1 [495 kB]
107.1 Get:2 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 odbcinst1debian2 arm64 2.3.11-1 [140 kB]
107.1 Get:3 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 odbcinst arm64 2.3.11-1 [21.8 kB]
107.1 Get:4 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 unixodbc arm64 2.3.11-1 [52.5 kB]
107.1 Get:5 https://packages.microsoft.com/ubuntu/20.04/prod focal/main arm64 msodbcsql18 arm64 18.3.2.1-1 [691 kB]
107.3 debconf: delaying package configuration, since apt-utils is not installed
107.3 Fetched 1400 kB in 1s (1827 kB/s)
107.4 Selecting previously unselected package libodbc1:arm64.
(Reading database ... 30450 files and directories currently installed.)
107.4 Preparing to unpack .../libodbc1_2.3.11-1_arm64.deb ...
107.4 Unpacking libodbc1:arm64 (2.3.11-1) ...
107.4 dpkg: error processing archive /var/cache/apt/archives/libodbc1_2.3.11-1_arm64.deb (--unpack):
107.4 trying to overwrite '/usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0', which is also in package libodbc2:arm64 2.3.9-5
107.4 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
107.4 Selecting previously unselected package odbcinst1debian2:arm64.
107.4 Preparing to unpack .../odbcinst1debian2_2.3.11-1_arm64.deb ...
107.4 Unpacking odbcinst1debian2:arm64 (2.3.11-1) ...
107.4 dpkg: error processing archive /var/cache/apt/archives/odbcinst1debian2_2.3.11-1_arm64.deb (--unpack):
107.4 trying to overwrite '/usr/lib/aarch64-linux-gnu/libodbcinst.so.2.0.0', which is also in package libodbcinst2:arm64 2.3.9-5
107.4 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
107.4 Selecting previously unselected package odbcinst.
107.4 Preparing to unpack .../odbcinst_2.3.11-1_arm64.deb ...
107.4 Unpacking odbcinst (2.3.11-1) ...
107.4 dpkg: error processing archive /var/cache/apt/archives/odbcinst_2.3.11-1_arm64.deb (--unpack):
107.4 trying to overwrite '/etc/odbc.ini', which is also in package unixodbc-common 2.3.9-5
107.4 Selecting previously unselected package unixodbc.
107.4 Preparing to unpack .../unixodbc_2.3.11-1_arm64.deb ...
107.4 Unpacking unixodbc (2.3.11-1) ...
107.4 Selecting previously unselected package msodbcsql18.
107.4 Preparing to unpack .../msodbcsql18_18.3.2.1-1_arm64.deb ...
107.5 Unpacking msodbcsql18 (18.3.2.1-1) ...
107.5 Errors were encountered while processing:
107.5 /var/cache/apt/archives/libodbc1_2.3.11-1_arm64.deb
107.5 /var/cache/apt/archives/odbcinst1debian2_2.3.11-1_arm64.deb
107.5 /var/cache/apt/archives/odbcinst_2.3.11-1_arm64.deb
107.5 E: Sub-process /usr/bin/dpkg returned an error code (1)
------
failed to solve: process "/bin/sh -c apt-get update && mkdir -p /etc/apt/keyrings && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null && echo \"deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main\" > /etc/apt/sources.list.d/ppa_ondrej_php.list && apt-get update && apt-get install -y php8.3-cli php8.3-dev php8.3-pgsql php8.3-sqlite3 php8.3-gd php8.3-curl php8.3-imap php8.3-mysql php8.3-mbstring php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap php8.3-intl php8.3-readline php8.3-ldap php8.3-msgpack php8.3-igbinary php8.3-redis php8.3-swoole php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && echo \"deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main\" > /etc/apt/sources.list.d/nodesource.list && apt-get update && apt-get install -y nodejs && npm install -g npm && npm install -g pnpm && npm install -g bun && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn.gpg >/dev/null && echo \"deb [signed-by=/etc/apt/keyrings/yarn.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 /etc/apt/keyrings/pgdg.gpg >/dev/null && echo \"deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-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/* && apt-get update && apt-get install -y --no-install-recommends apt-transport-https curl gnupg unixodbc-dev && 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 && ACCEPT_EULA=Y apt-get install -y msodbcsql18 && pecl install sqlsrv && pecl install pdo_sqlsrv && echo \"extension=sqlsrv.so\" > /etc/php/8.3/mods-available/sqlsrv.ini && echo \"extension=pdo_sqlsrv.so\" > /etc/php/8.3/mods-available/pdo_sqlsrv.ini && phpenmod -v 8.3 sqlsrv pdo_sqlsrv && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*" did not complete successfully: exit code: 100
After a few hours and doing some learning here is a working copy.
Was super helpful to go through and manually add the key and the repo after the image had booted.
Thanks for the help guys!
FROM ubuntu:22.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=20
ARG POSTGRES_VERSION=15
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& mkdir -p /etc/apt/keyrings \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.3-cli php8.3-dev \
php8.3-pgsql php8.3-sqlite3 php8.3-gd \
php8.3-curl \
php8.3-imap php8.3-mysql php8.3-mbstring \
php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap \
php8.3-intl php8.3-readline \
php8.3-ldap \
php8.3-msgpack php8.3-igbinary php8.3-redis php8.3-swoole \
php8.3-memcached php8.3-pcov php8.3-imagick php8.3-xdebug \
&& curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& npm install -g pnpm \
&& npm install -g bun \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn.gpg >/dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/yarn.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 /etc/apt/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-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/* \
&& apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
curl \
gnupg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc \
&& curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql18
RUN apt-get install -y unixodbc-dev
RUN pecl install sqlsrv \
&& pecl install pdo_sqlsrv \
&& echo "extension=sqlsrv.so" > /etc/php/8.3/mods-available/sqlsrv.ini \
&& echo "extension=pdo_sqlsrv.so" > /etc/php/8.3/mods-available/pdo_sqlsrv.ini \
&& phpenmod -v 8.3 sqlsrv pdo_sqlsrv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.3
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/8.3/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]