I have an existing Laravel project which I created with the following command.
curl -s https://laravel.build/example-app | bash
The project was created successfully and when I start it with command ./vendor/bin/sail up it works fine.
I want to clone the project on my second machine and start with sail. I found the following link from documentation which gives you possibility to run composer install even if you don't have composer installed on your OS.
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
This basically starts a docker container which has php and composer installed and runs composer install.
Installing packages work fine, but whenever I run ./vendor/bin/sail up then it throws errors and the application is not started.
It looks like some packages were not installed.
Has anyone had the same issue?
The problem is that you should update laravel/sail package first and then run composer install.
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer update laravel/sail
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
Related
Present are two files, Dockerfile.infra and docker-compose-infra.yml. Firstly, docker-compose-infra.yml is built via the following command:
docker-compose --file docker-compose-infra.yml build
This results in no errors and finishes as expected.
The problem arises when trying to deploy this to AWS. The following command:
docker-compose --file docker-compose-infra.yml run cdk
Produces this error:
bash: cdk: command not found
This appears to be triggered when the docker-compose-infra.yml attempts to run the cdk deploy bash command.
The command should run because within the Dockerfile.infra build, cdk is installed via npm install -g aws-cdk-lib.
Dockerfile.infra file:
FROM node:16-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN npm install -g aws-cdk-lib \
&& apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
# install Python
python3-pip \
# install Poetry via curl
curl \
&& curl -k https://install.python-poetry.org | python3 - \
&& apt-get remove curl -y \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
COPY pyproject.toml poetry.lock /
ENV PATH=/root/.local/bin:$PATH
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev
WORKDIR /app/
COPY app.py cdk.json cdk.context.json /app/
COPY stacks/ /app/stacks/
docker-compose-infra.yml:
version: "3"
services:
cdk:
command: bash -c "cdk deploy --require-approval never --all --parameters my-app-${ENVIRONMENT}-service:MyServiceImageTag=${IMAGE_TAG}"
build:
context: ./
dockerfile: Dockerfile.infra
environment:
- AWS_PROFILE=${AWS_PROFILE}
- ENVIRONMENT=${ENVIRONMENT}
- DEPLOY_ACCOUNT=${DEPLOY_ACCOUNT}
volumes:
- ~/.aws/credentials:/root/.aws/credentials
You need to install aws-cdk not aws-cdk-lib
RUN npm install -g aws-cdk \
This might be a bit confusing because aws-cdk-lib is also the name of the required Python dependency when writing Python CDK apps and a valid npm package.
Sail Version: 1.16.2
Laravel Version: 9.37
PHP Version: 8.1
Host operating system: macOS 12.3
Description:
I want to use Sail on my existing Laravel application.
As following to the documentation, i need to execute this command to install sail & other composer dependencies:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
When i run it, everything is going well until composer install crashes with this error:
Install of google/apiclient-services failed
In Filesystem.php line 314: Could not delete /var/www/html/vendor/composer/cc83f9bf/googleapis-google-api-php-client-services-52b4942/src/OrgPolicyAPI:
Steps To Reproduce:
Install new laravel application
Delete vendor folder if you have one
Add "google/apiclient": "^2.12.6" to your composer.json
Execute the docker run command above
Error occurs
Can someone help me solving this?
I am setting up a new Laravel project and automating the installation process using docker.
Everything works, but the problem here is that the PhpStorm doesn't recognize some namespaces because the vendor folder is a volume. I will show the files to understand them better.
docker-compose.yml
version: '3'
services:
laravel.test:
build:
dockerfile: Dockerfile
ports:
- '${APP_PORT:-8080}:80'
volumes:
- '.:/var/www/html'
- /var/www/html/vendor #HERE IS THE VOLUME FOR VENDOR
Dockerfile
FROM php:8.1.2-fpm
#INSTALL DEPENDENCIES
RUN apt-get update && apt-get install -y \
openssl \
build-essential \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
locales \
apt-transport-https \
wget \
lsb-release \
libxml2-dev \
ca-certificates \
git \
nano \
libonig-dev \
zip
#PGSQL
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
#Libraries required for Laravel
RUN docker-php-ext-install \
pdo_mysql \
bcmath \
ctype \
fileinfo \
iconv \
gd \
mbstring \
pdo_mysql \
xml \
pcntl
# Install composer
RUN php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
COPY ./ /var/www/html
# Copy code to $path
RUN composer install
EXPOSE 9000
CMD ["php-fpm"]
.dockerignore
vendor
So after building the image and running composer install, the vendor folder is created in the container with all dependencies and in the host machine but without subfolders, as we can see in the following image:
And when I try to import any namespace, I receive an error.
Nothing wrong in PHPStorm. Your vendor folder is empty.
I used to run docker-composer without mapping volume for vendor.
Remove the mapping and log in to service with bash and run the composer install
Steps
Remove the - /var/www/html/vendor volume mapping
Log in to service using docker exec -it laravel.test bash (FYI: It's better if you use container_name: search it.)
run the command composer install or composer update
Note: Before running remove the existing vendor folder.(delete or rename it _vendor for temp)
Wild guess: check you volums whether you defined volume.
I have Laravel Lumen project
I have a Dockerfile for it.
FROM alpine:3.7
RUN apk --no-cache add \
php7 \
php7-fpm \
php7-pdo \
php7-mbstring \
php7-xml \
php7-openssl \
php7-json \
php7-phar \
php7-zip \
php7-dom \
php7-session \
php7-zlib && \
php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" && \
php7 composer-setup.php --install-dir=/usr/bin --filename=composer && \
php7 -r "unlink('composer-setup.php');" && \
ln -sf /usr/bin/php7 /usr/bin/php && \
ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini
RUN set -x \
addgroup -g 82 -S www-data \
adduser -u 82 -D -S -G www-data www-data
COPY . /src
ADD .env.example /src/.env
WORKDIR /src
RUN chmod -R 777 storage
CMD php -S localhost:8000 -t public
I also have docker-compose.yml
version: '3'
services:
portalmodules:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000
When I run docker-compose up, everything seem success
Creating network "lumen_default" with the default driver
Building portalmodules
Step 1/9 : FROM alpine:3.7
3.7: Pulling from library/alpine
5d20c808ce19: Downloading [> ] 21.15k5d20c808ce19: Downloading [============================> ] 1.195M5d20c808ce19: Extracting [> ] 32.77kB5d20c808ce19: Extracting [=====================> ] 917.5kB5d20c808ce19: Extracting [==================================================>] 2.107MB5d20c808ce19: Pull complete
Digest: sha256:fea30b82fd63049b797ab37f13bf9772b59c15a36b1eec6b031b6e483fd7f252
Status: Downloaded newer image for alpine:3.7
---> 6d1ef012b567
Step 2/9 : LABEL maintainer "John Doe <john#site.com>"
---> Running in fb4f2dd6d1de
Removing intermediate container fb4f2dd6d1de
---> 8a45db7ddab9
Step 3/9 : RUN apk --no-cache add php7 php7-fpm php7-pdo php7-mbstring php7-xml php7-openssl php7-json php7-phar php7-zip php7-dom php7-session php7-zlib && php7 -r "copy('http://getcomposer.org/installer', 'composer-setup.php');" && php7 composer-setup.php --install-dir=/usr/bin --filename=composer && php7 -r "unlink('composer-setup.php');" && ln -sf /usr/bin/php7 /usr/bin/php && ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini
---> Running in 3de805731cad
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/19) Installing php7-common (7.1.17-r0)
(2/19) Installing ncurses-terminfo-base (6.0_p20171125-r1)
(3/19) Installing ncurses-terminfo (6.0_p20171125-r1)
(4/19) Installing ncurses-libs (6.0_p20171125-r1)
(5/19) Installing libedit (20170329.3.1-r3)
(6/19) Installing pcre (8.41-r1)
(7/19) Installing libxml2 (2.9.8-r1)
(8/19) Installing php7 (7.1.17-r0)
(9/19) Installing php7-dom (7.1.17-r0)
(10/19) Installing php7-fpm (7.1.17-r0)
(11/19) Installing php7-json (7.1.17-r0)
(12/19) Installing php7-mbstring (7.1.17-r0)
(13/19) Installing php7-openssl (7.1.17-r0)
(14/19) Installing php7-pdo (7.1.17-r0)
(15/19) Installing php7-phar (7.1.17-r0)
(16/19) Installing php7-session (7.1.17-r0)
(17/19) Installing php7-xml (7.1.17-r0)
(18/19) Installing libzip (1.3.0-r1)
(19/19) Installing php7-zip (7.1.17-r0)
Executing busybox-1.27.2-r11.trigger
OK: 25 MiB in 32 packages
All settings correct for using Composer
Downloading...
Composer (version 1.8.4) successfully installed to: /usr/bin/composer
Use it: php /usr/bin/composer
Removing intermediate container 3de805731cad
---> ff5d58488a6d
Step 4/9 : RUN set -x addgroup -g 82 -S www-data adduser -u 82 -D -S -G www-data www-data
---> Running in 634b56b930cd
Removing intermediate container 634b56b930cd
---> 395f7f861700
Step 5/9 : COPY . /src
---> 0b4e7b92df73
Step 6/9 : ADD .env.example /src/.env
---> 2848f770f17d
Step 7/9 : WORKDIR /src
---> Running in cbba620f9904
Removing intermediate container cbba620f9904
---> 819ee9222de7
Step 8/9 : RUN chmod -R 777 storage
---> Running in 135b707d5008
Removing intermediate container 135b707d5008
---> 4bf78fca1236
Step 9/9 : CMD php -S localhost:8000 -t public
---> Running in 55d0a643fb43
Removing intermediate container 55d0a643fb43
---> bb0d3d1da9a9
Successfully built bb0d3d1da9a9
Successfully tagged lumen_portalmodules:latest
WARNING: Image for service portalmodules was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating lumen_portalmodules_1 ... done
Attaching to lumen_portalmodules_1
portalmodules_1 | PHP 7.1.17 Development Server started at Fri Mar 29 20:16:45 2019
But I don't what is the URL - I should go to see my site ... 🤦🏻♂️
I've tried go to : http://localhost:8000/
I kept getting this
Am I doing anything wrong ? What is my site URL ?
Have you tried : CMD php -S 0.0.0.0:8000 -t public ?
localhost is refering to the container local ip not your host machine's
This question has been asked here in many ways, but none of them seemed to be exactly what I'm looking for. Note: I'm totally new to Docker.
I've currently got a Docker image ("padcrawler") on my Mac, which is an image built off of scrapinghub/splash.
I'm basically just trying to make it so that any changes I make on my host machine (Mac), are automatically updated within the container. I'm using docker-machine and NOT boot2docker.
This is my Dockerfile:
FROM scrapinghub/splash:latest
# Update UBUNTU base image and install deps
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
build-essential \
ca-certificates \
gcc \
git \
libpq-dev \
make \
libxml2-dev \
libxslt-dev \
libssl-dev \
libffi-dev \
zlib1g-dev \
python-pip \
python \
python-dev \
ssh \
&& apt-get autoremove \
&& apt-get clean
RUN mkdir -p /usr/src/pad
WORKDIR /usr/src/pad
# Copy over everything to container directory
COPY . /usr/src/pad
# Install Python (2.7) deps
RUN /usr/bin/pip install -r /usr/src/pad/requirements.txt
# Launch pad-crawler upon docker container bootup
ENTRYPOINT /usr/src/pad/start
I'm also using docker-compose and this is my yml file:
version: '2'
services:
crawler:
build: .
volumes:
- ".:/usr/src/pad"
image: padcrawler
However, I'm still unable to get any host file changes to automatically sync with the mounted volume in the container. Obviously it's annoying and frustrating to have to manually copy over the changes every-time. Is there a bigger issue here? I'm using Docker totally wrong?