7

I'm trying to use a docker image with Laravel + Microsoft SQL drivers.

My dockerfile:

FROM php:7.2-apache

ENV ACCEPT_EULA=Y

# Microsoft SQL Server Prerequisites
RUN apt-get update \
    && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
    && curl https://packages.microsoft.com/config/debian/9/prod.list \
        > /etc/apt/sources.list.d/mssql-release.list \
    && apt-get install -y --no-install-recommends \
        locales \
        apt-transport-https \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
    && locale-gen \
    && apt-get update \
    && apt-get -y --no-install-recommends install \
        unixodbc-dev \
        msodbcsql17

RUN docker-php-ext-install mbstring pdo pdo_mysql \
    && pecl install sqlsrv pdo_sqlsrv xdebug \
    && docker-php-ext-enable sqlsrv pdo_sqlsrv xdebug

COPY index.php /var/www/html/


# We need a user with the same UID/GID as the host user
# so when we execute CLI commands, all the host file's permissions and ownership remain intact.
# Otherwise commands from inside the container would create root-owned files and directories.
ARG uid
RUN useradd -G www-data,root -o -u $uid -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
    chown -R devuser:devuser /home/devuser

When building using docker-compose build, I am getting invalid user:

useradd: invalid user ID '-d'
The command '/bin/sh -c useradd -G www-data,root -o -u $uid -d /home/devuser devuser' returned a non-zero code: 3
Joundill
  • 6,828
  • 12
  • 36
  • 50
Felipe Novaes
  • 73
  • 1
  • 5
  • 2
    In shell, `$something` is a variable. You have not defined `$uid`, so it ends up being an empty string, and so the command ends up being `useradd -G www-data,root -o -u -d /home/devuser devuser` – β.εηοιτ.βε Nov 14 '20 at 18:33
  • 1
    You should have a "default" assignation to cope with this issue if you forget to specify it at build time, something like `ARG uid=123` – β.εηοιτ.βε Nov 14 '20 at 18:35
  • Then what do you think it's the best way to solve this? – Felipe Novaes Nov 14 '20 at 18:56
  • 1
    As said in the comment above, either put a default value in the argument of your *Dockerfile*, or do not forget to pass [the correct argument](https://docs.docker.com/compose/compose-file/#build) in your *docker-compose.yml* – β.εηοιτ.βε Nov 14 '20 at 19:00

3 Answers3

2

In my case the reason was, that I tried to build the image directly using

docker build --tag imagename .

instead of using

docker-compose build app

from where the $uid value was supplied.

frankfurt-laravel
  • 3,731
  • 2
  • 20
  • 29
2

You have to specify the UID in your .env file like:

UID=1000

if you do not know the UID of your user, type id into your terminal

Stefano Borzì
  • 1,019
  • 1
  • 15
  • 32
0

Setting a default value to your ARG uid can works:

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 28 '21 at 16:18