I am working on a quizz app. I have installed the Laravel app on docker and when I started working on the app I noticed that it takes very long for the app to load. It takes ~7-8s to load a page with a form which have 5 inputs.
I know that this waiting time is very long because a few weeks ago I installed a laravel application on docker that moves very quickly. But I can no longer use that one. I think it is possible that it is due to the .yml file and the Dockerfile, but I don't know what the installation problems would be.
I can not disable the Use the WSL 2 based engine (Windows Home can only run the WSL 2 backend) from Docker UI because I run W10 Home.
docker-compose.yml
version: '3'
services:
mariadb:
image: mariadb
restart: always
ports:
- 3375:3306
environment:
TZ: "Europe/Bucharest"
MARIADB_ALLOW_EMPTY_PASSWORD: "no"
MARIADB_ROOT_PASSWORD: "user#pass"
MARIADB_ROOT_HOST: "%"
MARIADB_USER: 'user'
MARIADB_PASSWORD: 'pass'
MARIADB_DATABASE: 'db'
networks:
- sail
volumes:
- ./docker-config/server_bd:/var/lib/mysql
app:
build: ./docker-config
container_name: app
ports:
- 8000:80
- 4430:443
volumes:
- "./:/var/www/html"
tty: true
networks:
- sail
links:
- mariadb
depends_on:
- mariadb
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
networks:
- sail
links:
- "mariadb:db"
depends_on:
- mariadb
environment:
UPLOAD_LIMIT: 1024M
ports:
- 3971:80
networks:
sail:
driver: bridge
volumes:
data:
driver: local
Dockerfile
FROM ubuntu:20.04
EXPOSE 80
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=Europe/Bucharest
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt install -y lsb-release
RUN apt-get clean all
RUN apt-get install ca-certificates apt-transport-https -y
RUN apt-get install software-properties-common -y
# Apache Server
RUN apt-get -y install apache2
RUN a2enmod rewrite
RUN service apache2 restart
# SETUP SSL
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
a2enmod rewrite &&\
a2enmod ssl
COPY cert/certificate.crt /etc/ssl/certificate.crt
COPY cert/private.key /etc/ssl/private.key
COPY cert/ca_bundle.crt /etc/ssl/ca_bundle.crt
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
RUN service apache2 restart
RUN apt-get install -y wget
RUN apt-get install nano
RUN apt-get update -y
RUN apt-get install -y apt-transport-https
# PHP8
RUN add-apt-repository ppa:ondrej/php
RUN apt-get install -y php8.1
RUN apt-get install -y php8.1-fpm
RUN apt-get install -y libapache2-mod-php
RUN apt-get install -y libapache2-mod-fcgid
RUN apt-get install -y curl
RUN apt-get install -y php-curl
RUN apt-get install -y php-dev
RUN apt-get install -y php-gd
RUN apt-get install -y php-mbstring
RUN apt-get install -y php-zip
RUN apt-get install -y php-xml
RUN apt-get install -y php-soap
RUN apt-get install -y php-common
RUN apt-get install -y php-tokenizer
RUN apt-get install -y unzip
RUN apt-get install -y php-bcmath
RUN apt-get install -y php-mysql
# Install npm
RUN apt-get install -y npm
RUN npm cache clean -f
RUN npm install -g n
RUN n stable
RUN service apache2 restart
# COMPOSER
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN echo " extension = php_mysqli.so" >> /etc/php/8.1/apache2/php.ini
RUN service apache2 restart
CMD ( cron -f -l 8 & ) && apachectl -D FOREGROUND
The DB is working fine, at a good speed.
The laptop power is not an issue because on the last app everything was running smooth and with no problems.
So I noticed that in WSL2 it is the filesystem which is an issue. If your project is on a folder in the Windows file system it will run much more slower than if you put the entire project into the Linux file system. Try moving your project into the linux system and see if it speeds it up.
For example, if your project is located in a windows folder like
C:\Projects\FooBar
Move it to the linux filesystem under WSL2 to something like:
/home/YouName/projects/FooBar
After you have done this - rebuild the container from the new location.
Related
I want to run a apache webserver with php extension inside container using docker compose as deployment.
My compose file looks like this:
version: '3.1'
services:
php:
image: php:7.2-apache
ports:
- 8089:80
volumes:
- ./php/www:/var/www/html/
how can I enable the following extensions.
apache2
php7.2
php-xdebug
php7.2-mcrypt
php-apcu
php-apcu-bc
php7.2-json
php-imagick
php-gettext
php7.2-mbstring
First of all you can run php -m in php container to see installed and enabled modules.
You can edit your docker-compose.yml like this:
version: '3.1'
services:
php:
# image: php:7.2-apache # remember to comment this line
build: .
ports:
- 8089:80
volumes:
- ./php/www:/var/www/html/
Create a file called Dockerfile beside docker-compose.yml with the following contents:
FROM php:7.2-apache
# then add the following `RUN ...` lines in each separate line, like this:
RUN pecl install xdebug && docker-php-ext-enable xdebug
...
Finally, let's go one by one:
apache2
Is installed.
php7.2
Is enabled.
php-xdebug
Add Dockerfile:
RUN pecl install xdebug && docker-php-ext-enable xdebug
php7.2-mcrypt
Add to Dockerfile:
RUN apt-get install libmcrypt-dev
RUN pecl install mcrypt && docker-php-ext-enable mcrypt
php-apcu
Add to Dockerfile:
RUN pecl install apcu && docker-php-ext-enable apcu
php-apcu-bc
Add to Dockerfile:
RUN pecl install apcu_bc
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN echo 'extension=apc.so' >> /usr/local/etc/php/php.ini
php7.2-json
Is installed.
php-imagick
Add to Dockerfile:
RUN apt install -y libmagickwand-dev --no-install-recommends && \
pecl install imagick && docker-php-ext-enable imagick
php-gettext
RUN docker-php-ext-install gettext && \
docker-php-ext-enable gettext
php7.2-mbstring
Is enabled.
Hello i have a docker container running which has my laravel app, i'm using my database from my local machine. I dont have extra container for my DB. But unfortunately i cannot connect my docker container with my mysql DB.
Here is the docker file
FROM ubuntu:bionic
RUN apt-get update && apt-get -y upgrade && apt-get install -y software-properties-common tzdata
RUN echo "Asia/Dhaka" > /etc/timezone && rm -f /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN add-apt-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt install -y wget php8.0 php8.0-fpm php8.0-common php8.0-mysql php8.0-xml php8.0-dev php8.0-xmlrpc php8.0-curl php8.0-mbstring php8.0-zip
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN mv composer.phar /usr/local/bin/composer
RUN apt-get install -y php8.0-mongodb unzip
RUN apt-get install -y mysql-client
WORKDIR /app
COPY . .
EXPOSE 3306
and here is my docker-compose.yml file
version: "3"
services:
client:
build: ./
command: tail -f /dev/null
ports:
- 5500:8000
volumes:
- ./:/app
entrypoint: ./init.sh
when i try to access my DB inside from my Container it says
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
when i try to run my **api through postman** it gives me this
{
"status": "failure",
"data": [],
"error_code": 400,
"error_message": "Something went Wrong",
"errors": "SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `users` where `email` = example#gmail.com limit 1)"
}
What might be the issue? my laravel app should get access from the container because i have exposed the port 3306 on my container. I have configured .env file but still i can not access the database from my application. I enter the container by docker exec and try to connect the DB but it cannot connect. So can anyone tell me that what i'm missing?
Thanks in Advance
I am using lmc-eu/steward to write test cases with selenium server in php i am running this test cases direct command that is working fine but as i have added it in bitbucket pipeline then its giving error
Error :
Browser: chrome
Environment: test
Base path to fixtures results: /ws/annotator-php/tests
Path to logs: /ws/annotator-php/logs
Ignore delays: no
Selenium server (hub) url: http://localhost:4444, trying connection...connection error ("Cannot assign requested address")
[ERROR] Make sure your Selenium server is really accessible on url
"http://localhost:4444" or change it using --server-url option
This is my bitbucket pipeline step
step (image: ubuntu:16.04) :
# script:
- apt-get update -y
- apt-get install openjdk-8-jre -y
- apt-get install -y python-software-properties software-properties-common curl openjdk-8-jre-headless
- LANG=C.UTF-8 add-apt-repository ppa:ondrej/php
- apt-get update -y
- # php install
- apt-get install php5.6 php5.6-zip libapache2-mod-php5.6 php5.6-cgi php5.6-cli php5.6-curl php5.6-imap php5.6-gd php5.6-mysql php5.6-pgsql php5.6-sqlite3 php5.6-mbstring php5.6-json php5.6-bz2 php5.6-mcrypt php5.6-xmlrpc php5.6-gmp php5.6-xsl php5.6-soap php5.6-xml php5.6-zip php5.6-dba php5.6-bcmath -y
- curl -sS https://getcomposer.org/installer -o composer-setup.php && php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- #Chrome Install
- curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
- dpkg -i /chrome.deb || apt-get install -yf
- rm /chrome.deb
# install chromedriver
- apt-get install -yqq unzip
- wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
- unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# set display port to avoid crash
- export DISPLAY=:99
- SDK_VERSION=230.0.0
- SDK_FILENAME=google-cloud-sdk-${SDK_VERSION}-linux-x86_64.tar.gz
- curl -O -J https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${SDK_FILENAME}
- tar -zxvf ${SDK_FILENAME} --directory ${HOME}
- export PATH=${PATH}:${HOME}/google-cloud-sdk/bin
- ${HOME}/google-cloud-sdk/bin/gcloud --version
- ${HOME}/google-cloud-sdk/bin/gcloud components list
- ${HOME}/google-cloud-sdk/bin/gcloud components install app-engine-php --quiet
- cd annotator-php
- apt-get update -y
- ${HOME}/google-cloud-sdk/bin/dev_appserver.py app.yaml --php_executable_path /usr/bin/php-cgi &
- Xvfb :0 -ac -screen 0 1024x768x24 &
- java -Dwebdriver.chrome.driver=/tmp/chromedriver -jar tests/selenium-server-standalone-3.141.59.jar -port 4444 &
- ./vendor/bin/steward run test chrome -vvv
Maybe you want to revew the step where you spin up chromedriver, updating the version.
My command looks like this:
java -jar -Dwebdriver.chrome.driver="./vendor/selenium/chromedriver" -jar ./vendor/selenium/selenium-server-4.0.0.jar standalone
Haven't put that into a pipeline though. For that you might want to use docker-selenium
I'm changing infrastructure on AWS and I want to use Docker (ECS) with Fargate. My Docker image is based on Ubuntu and I install all I need in it. I'm using Laravel 5.6 on NGINX running PHP 7.2. My Docker container works on my local machine and if I run ECS with EC2, however when I change to Fargate it returns NGINX 500 error. I did some tests and I know PHP is running, only when I install my Laravel app the error happens.
Since I cannot access Fargate machine I don't know how to debug. I tryied to connect NGINX with Loggly however it requires rsyslog and since I'm using Docker it cannot access Ubuntu's core. When I install and try to run it returns:
rsyslogd: imklog: cannot open kernel log (/proc/kmsg): Operation not permitted
Here is my Dockerfile:
FROM ubuntu:latest
ENV BACKEND_PATH=/code/Backend
ENV FRONTEND_PATH=/code/Frontend
## Update
RUN apt-get update -y
## Upgrade
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:certbot/certbot
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get autoremove -y
RUN apt-get update -y
## Nano
RUN apt-get install -y nano
## Timezone
RUN echo "America/Sao_Paulo" > /etc/timezone && \
apt-get install -y tzdata && \
rm /etc/localtime && \
ln -snf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get clean
## Git
RUN apt-get install -y git
## NGINX
RUN apt-get install -y nginx
COPY ./nginx/app/sites-available /etc/nginx/sites-available
COPY ./nginx/app/sites-available /etc/nginx/sites-enabled
COPY ./nginx/sites /etc/nginx/sites
COPY ./nginx/ssl /ssl
## PHP
RUN apt-get install -y php-cli php-fpm php-curl php-mbstring
COPY ./php/php.ini /usr/local/etc/php
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install libs
RUN apt-get install -y php-zip php-mysql php-gd pngquant gifsicle jpegoptim libicu-dev g++ php-intl php-xml
## Crontab
RUN apt-get install -y cron
COPY crontab newcrontab
RUN crontab newcrontab
RUN rm newcrontab
## Supervisor
RUN apt-get install -y supervisor
COPY ./supervisord /etc/supervisor/conf.d
## Certbot
RUN apt-get install -y python-certbot-nginx
## Install apps
COPY ./code/Backend /code/Backend
COPY ./code/Frontend/dist /code/Frontend/dist
RUN cd ${BACKEND_PATH} && chmod +x composer.phar && ./composer.phar self-update && php composer.phar install
RUN chmod -Rf 777 ${BACKEND_PATH}/storage
RUN chmod -Rf 777 ${BACKEND_PATH}/resources
RUN php ${BACKEND_PATH}/artisan config:clear
RUN php ${BACKEND_PATH}/artisan passport:keys
## Run!
EXPOSE 80 443
RUN service php7.2-fpm start
CMD ["/usr/bin/supervisord"]
I think this error has something to do with permissions but without error message it's almost impossible to know what's going on... Does anyone have any ideia how I may find this out?
I figured it out. Really stupid mistake actually. When I created Fargate configurations I used a Security Group without permissions to access some AWS components so the application was unable to boot.
Check out this answer on ServerFault: https://serverfault.com/questions/691048/kernel-log-stays-empty-rsyslogd-imklog-cannot-open-kernel-log-proc-kmsg
Try running the Fargate task with the --privileged flag. You can set this flag in the AWS console per-container in the task definition. It's in the SECURITY section near the end of the container definition. Here's the full reference for container definitions.
I am trying to setup PHP 5.6.30 fp, but i got error.
Error the same as here (Docker) Getting error: docker-php-source: no such file or directory when building docker file
But i can`t understand how to resolve this.
my folder looks like
app
--docker
--workspace
inside workspace Dockerfile i paste all from https://github.com/docker-library/php/blob/eadc27f12cfec58e270f8e37cd1b4ae9abcbb4eb/5.6/fpm/Dockerfile
Step 15/22 : COPY docker-php-source /usr/local/bin/
ERROR: Service 'workspace' failed to build: lstat docker-php-source: no such file or directory
So what i must to do?
i did this command docker pull php before and it is not helped.
So i have this .yml file
version: '2'
services:
app:
build: ./docker/app
volumes:
- .:/var/www/html
command: "true"
workspace:
build: ./docker/workspace
volumes_from:
- app
links:
- php
- nginx
tty: true
depends_on:
- app
nginx:
build: ./docker/nginx
ports:
- 8080:80
links:
- php
volumes_from:
- app
php:
build: ./docker/php
expose:
- "9000"
volumes_from:
- app
mysql:
image: mysql:5.7
volumes_from:
- app
expose:
- "3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
MYSQL_USER: root
MYSQL_PASSWORD: root
memcached:
image: memcached
ports:
- "11211:11211"
inside workspace/Dockerfile i have all strings from github image 6.6.30fpm
Then inside this folder i do
docker-compose build workspace
Before this in workspace i had another settings
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget nano locate
RUN apt-get update --fix-missing --allow-unauthenticated
RUN apt-get install -y --allow-unauthenticated libmcrypt-dev libxml2-dev mysql-client
RUN apt-get update -y --allow-unauthenticated && apt-get upgrade -y --allow-unauthenticated && apt-get install -q -y php5 php5-dev php5-fpm php5-mysqlnd php5-mcrypt
RUN echo "extension=/usr/lib/php5/20121212/mcrypt.so" > /etc/php5/mods-available/mcrypt.ini \
&& ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/cli/conf.d/20-mcrypt.ini
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
WORKDIR /var/www/html
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
and this works but i want to 5.6.30 instead of 5.5.9
Perhaps it is due to the fact that there is no permission to execute.
Try
chmod +x docker-php-*
UPD:
Just put all these files inside directory with your php 5.6 Dockerfile
If you want to use php 7.2 version, this link is for you
Anyway for other googlers. Just explore this repository and you will find that you want. :)