unable to find user sail: no matching entries in passwd file - laravel

Please I'm working with Laravel on Docker, trying to run the sail command
./vendor/bin/sail composer install
in order to manage the laravel packages and install Tailwind CSS but it keeps sowing this message:
unable to find user sail: no matching entries in passwd file
I wonder what I'm missing! here is my docker-compose.yml file
version: '2.0'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: abdelazizmirasoft/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html/
volumes:
- ./:/var/www/html/
- ./php/laravel.ini:/usr/local/etc/php/conf.d/laravel.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver-upwork
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/html/
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.32
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
my .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:5ndGfShEF7w6wfnnzMlGrG7A9IFOJrlh9G7VVw0BTgM=
APP_DEBUG=true
APP_URL=http://localhost
APP_SERVICE=app
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=upwork_clone
DB_USER=upwork_user
DB_PASSWORD=p#$sw0rd
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello#example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
and the Dockerfile
FROM php:8.0.5-fpm
# Copy composer.lock and composer.json into the working directory
COPY composer.lock composer.json /var/www/html/
# Set working directory
WORKDIR /var/www/html/
# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
libzip-dev \
unzip \
git \
libonig-dev \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions for php
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy existing application directory contents to the working directory
COPY . /var/www/html
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
/var/www/html/storage \
/var/www/html/bootstrap/cache
# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
EXPOSE 9000
CMD ["php-fpm"]
Anyone can help with that?
Thanks

Laravel provides Sail, a built-in solution for running your Laravel project using Docker.
Laravel Sail is a Docker development environment included by default in Laravel since version 8. It allows you to quickly get a PHP development environment up and running, tailored for running Laravel applications with built-in support for NPM / Node.
So in order to build your containers properly I recommend to read about this article: How To Build a Responsive About Me Page with Laravel, Sail, and Tailwind CSS

Related

Laravel 9 with Docker - CSS and JS not loading using Vite

I'm having trouble in determining the cause of not loading of my CSS stylesheet and Javascript on my Laravel 9 project using Docker in my Windows OS.
I have done all the steps after creating containers and no error message thrown in my page.
Should I run npm run dev in the container? I have no issue before using mix but I really need to deploy this project.
I also attached screenshot below from chrome dev tools that everything in my app.js & app.css is not loading
Dockerfile:
# Set master image
FROM php:8.0-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN chown -R www-data:www-data /var/www
# Set working directory
WORKDIR /var/www
USER $user
docker-compose.yml
version: '3'
services:
#Laravel App
app:
build:
context: .
dockerfile: Dockerfile
image: dr3
container_name: app
volumes:
- .:/var/www/
ports:
- "9000:9000"
networks:
- laraveldockerize
#Nginx Service
nginx:
image: nginx:stable-alpine
container_name: nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- .:/var/www
- ./dockerize/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laraveldockerize
#MySQL Service
db:
image: mysql:5.7
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
# MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
volumes:
- ./dockerize/mysql/data:/var/lib/mysql
- ./dockerize/mysql/my.cnf:/etc/mysql/conf.d/mysql-custom.cnf
networks:
- laraveldockerize
node:
image: node:alpine
container_name: node
working_dir: /var/www/
tty: true
ports:
- 5173:5173
volumes:
- ./:/var/www
networks:
- laraveldockerize
#Docker Networks
networks:
laraveldockerize:
driver: bridge
Vite:

Docker build with laravel - SQLSTATE[HY000] [2002]

I'm getting error with my docker image after building the docker containers.
on docker-compose up -d command, the application is connected to a database.
but when I tried to run docker build -t to make an image
and run it, I got 500 internal error php_network_getaddresses: getaddrinfo failed:
FROM webdevops/php-nginx:7.4-alpine
WORKDIR /app
# Install Laravel framework system requirements (https://laravel.com/docs/8.x/deployment#optimizing-configuration-loading)
RUN apk add oniguruma-dev postgresql-dev libxml2-dev
RUN docker-php-ext-install \
bcmath \
ctype \
fileinfo \
json \
mbstring \
pdo_mysql \
pdo_pgsql \
tokenizer \
xml
# Copy Composer binary from the Composer official Docker image
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV WEB_DOCUMENT_ROOT /app/public
ENV APP_ENV production
# Copy existing application directory contents to the working directory
COPY . .
RUN composer install
RUN composer install --no-interaction --optimize-autoloader --no-dev
# Optimizing Configuration loading
RUN php artisan config:clear
# Optimizing Route loading
RUN php artisan cache:clear
RUN php artisan view:cache
RUN chown -R application:application .
for additional details here is my docker-compose.yml
version: "3.8"
services:
#php service
php:
build:
context: .
dockerfile: Dockerfile
container_name: dtltrcy_phpv1
volumes:
- .:/var/www/html
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- laravel
#nginx service web server
nginx:
image: nginx:stable-alpine
container_name: dtltrcy_nginxv1
ports:
- "8080:80"
volumes:
- .:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- dataliteracyapp
#mysql service
mysql:
image: mysql:8.0.21
container_name: dtltrcy_mysqlv1
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
environment:
MYSQL_DATABASE: database
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_HOST: '%'
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
container_name: dtltrcy_phpmyadminv1
depends_on:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
networks:
- laravel
#docker networks
networks:
laravel:
.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=secret
I tried to change .env file with these.
DB_HOST=127.0.0.1 ERROR -> SQLSTATE[HY000] [2002] Connection refused
DB_HOST=localhost ERROR -> SQLSTATE[HY000] [2002] No such file or directory
DB_HOST=172.19.0.3 ERROR -> SQLSTATE[HY000] [2002] Operation time out
Container IP using docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id
I was facing a similar issue, this is my Dockerfile and it works fine.
FROM php:8-apache
WORKDIR /var/www/html
# install the necessary packages
RUN apt-get update -y && apt-get install -y \
curl \
nano \
npm \
g++ \
git \
zip \
vim \
sudo \
unzip \
nodejs \
libpq-dev \
libicu-dev \
libbz2-dev \
libzip-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql \
&& docker-php-ext-install mysqli pdo_mysql \
&& docker-php-ext-enable mysqli
RUN docker-php-ext-install \
zip \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar
# copy the config file over
#COPY /server/apache/ports.conf /etc/apache2/ports.conf
COPY /server/apache/vhost.conf /etc/apache2/sites-available/laravel.conf
#COPY 000-default.conf /etc/apache2/sites-enabled/000-default.conf
#COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
# install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# use custom configuration and disable built-in one
#RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN a2enmod rewrite
RUN a2ensite laravel.conf
RUN a2dissite 000-default.conf
# copy over the project files
COPY . /var/www/html
# change ownership of the files
RUN chown -R www-data:www-data /var/www
RUN cd /var/www/html && npm instal && composer install && php artisan optimize
CMD ["/var/www/html/scripts/start-apache.sh"]
/scripts/start-apache.sh
#!/usr/bin/env bash
sed -i "s/Listen 80/Listen ${PORT:-80}/g" /etc/apache2/ports.conf
sed -i "s/:80/:${PORT:-80}/g" /etc/apache2/sites-enabled/*
apache2-foreground "$#"
/server/apache/vhost.conf (not relevant for your issue though, it is for changing the document root)
<VirtualHost *:80>
DocumentRoot /var/www/html/public
<Directory "/var/www/html/public">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
docker-compose.yml
version: "2"
services:
laravel-app:
build:
context: '.'
dockerfile: Dockerfile
environment:
- MYSQL_DATABASE=routes-db
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- MYSQL_PASSWORD=""
container_name: laravel-app
volumes:
- ./:/var/www/html
ports:
- "8000:80"
networks:
- laravel-app-network
depends_on:
- db
db:
image: mysql:5.7
ports:
- "3306:3306"
environment:
- MYSQL_DATABASE=routes-db
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- MYSQL_PASSWORD=""
volumes:
- "./db:/var/lib/mysql"
networks:
- laravel-app-network
networks:
laravel-app-network:
driver: bridge
volumes:
mysql_data:
driver: local
If I remember correctly, it was either something to do with either the packages/libraries or permissions. Check the line:
RUN chown -R www-data:www-data /var/www
It makes sure you got the right permissions.
Sorry that I couldn't give more details.

Why is my Docker volume only sharing the docker-compose file?

I am trying to containerize a Laravel application using Docker Compose, but I am failing to use a shared volume to bring in my actual project app files. My docker-compose file looks like this:
version: "3.7"
services:
app:
build:
args:
user: sam
uid: 1000
context: ./
dockerfile: Dockerfile
image: converter
container_name: converter-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- converter
db:
image: mysql:5.7
container_name: converter-db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- converter
nginx:
image: nginx:alpine
container_name: converter-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- converter
networks:
converter:
driver: bridge
volumes:
app-volume:
and the Dockerfile for the app service:
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
I then run docker-compose build app and docker-compose up -d to create the containers, which brings them up. When I go to check the /var/www folder of the app container using docker-compose exec app ls -l, the only file that shows is the docker-compose file:
Shouldn't the shared volume specified for the app service share my working directory in the app /var/www folder?
You need to add these config options to the app service in compose file:
links:
- nginx
depends_on:
- nginx
These options forces docker-compose to create 1st the nginx service, and after the app, this is neccessary becuse currently nginx is created after app, and nging overwrite the /var/www directory

Laravel Not Found, Docker, Apache2

I am traying to connect to my container but I am getting the following error. Before my container works without problems. I made a new build but it doesn’t work.
My Docker file is the following:
FROM php:7.2-apache
LABEL maintainer="christianahvilla#gmail.com"
# Install PHP
RUN apt-get update && apt-get install -y \
curl \
zlib1g-dev \
libzip-dev \
nano
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql
RUN docker-php-ext-install zip
# # Install PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
#set our application folder as an environment variable
ENV APP_HOME /var/www/html
#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
COPY --chown=www-data:www-data . $APP_HOME
#Expose Port 8000 since this is our dev environment
EXPOSE 8000
My Docker-Compose:
version: "3.7"
services:
#Laravel App
web:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:80
volumes:
- ./:/var/www
- ./public:/var/www/html
networks:
- mynet
depends_on:
- db
#MySQL Service
db:
image: mysql:5.7
container_name: db
ports:
- 3306:3306
environment:
MYSQL_DATABASE:
MYSQL_USER:
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD:
volumes:
- mysqldata:/var/lib/mysql/
networks:
- mynet
#Docker Networks
networks:
mynet:
driver: bridge
#Volumes
volumes:
mysqldata:
driver: local
When I try to access to http:localhost:8000/ I can do it but if I try to access to another route I get the error.
You have to configure the apache2.conf in /etc/apache2/apache2.conf from Dockerfile, and also a2endmode rewrite, finally you need to restart apache2:
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
RUN a2enmod rewrite
RUN service apache2 restart
Then run docker-compose build and docker-compose up -d

Docker Laravel not loading assets

I have configure a docker compose file to run laravel with apache and mysql. The app builds fine but when i access to it i have this error loading the assets
This is my docker-compose file conf:
version: '3'
services:
#PHP Service
vma_web:
build:
context: .
dockerfile: Dockerfile
container_name: vma_web
restart: unless-stopped
env_file: '.env.prod'
tty: true
ports:
- "8250:80"
environment:
SERVICE_NAME: vma_web
SERVICE_TAGS: 1.0.0
networks:
- app-network
#MySQL Service
vma_mysql:
image: mysql:5.7
container_name: vma_mysql
restart: unless-stopped
tty: true
ports:
- "33061:3306"
environment:
MYSQL_DATABASE: school_back
MYSQL_ROOT_PASSWORD: epTfkgH9XakwN5mm
SERVICE_TAGS: 1.0.0
SERVICE_NAME: vma_mysql
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
And the dockerfile
FROM php:7.2-apache-stretch
RUN apt-get update
RUN apt-get install -y libpng-dev libxml2-dev nano zip unzip
RUN docker-php-ext-install mbstring gd zip pdo pdo_mysql
COPY vma.conf /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www/html/vma
COPY . .
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod -R 777 bootstrap storage public routes/pages.php
RUN composer install
EXPOSE 80
What am i doing wrong ?
is something about permissions ?
is something about the ports ?

Resources