I have a problem with composer install on docker. This is my docker-compose file:
version: '3'
services:
webserver:
image: nginx:latest
ports:
- 80:80
- 433:433
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./:/var/www/html/
links:
- php-fmp
- db
networks:
- app-network
php-fmp:
build: docker/php-fmp
volumes:
- ./:/var/www/html/
ports:
- 9000:9000
links:
- db
networks:
- app-network
db:
image: mysql
ports:
- 3306:3306
volumes:
- /var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_DATABASE=goexpress
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_ROOT_PASSWORD=docker
networks:
- app-network
networks:
app-network:
driver: bridge
I try to execute docker-compose run php-fmp composer install it starts after some minutes it shows memory limit xxxxxxxxx. I have tried also memory_limit=-1.
My laptop memory: 6GB.
In another pc it works perfect.
Before upgrade of memory it has worked. Memory before was 4GB now it is 6GB. The project that I want to run is symfony.
Composer has its own COMPOSER_MEMORY_LIMIT environment variable, but uses php.ini's memory_limit by default when its own variable is not set. https://getcomposer.org/doc/03-cli.md#composer-memory-limit
With Docker Compose you will need to pass COMPOSER_MEMORY_LIMIT as an environment variable to the container where Composer is installed. Your docker-compose.yml file would look like this:
services:
php-fmp: //the name of your container (as per your question)
environment:
- COMPOSER_MEMORY_LIMIT=-1 //-1 means unlimited
This environment variable would be taken into account every time you run Composer with docker-compose:
docker-compose exec php-fmp composer [your composer command]
Instead of php -d memory_limit=-1 composer install try COMPOSER_MEMORY_LIMIT=-1 composer install. Composer starts a new php process, that does not adhere to the setting you provide and it might even override the config (I'm not a 100% sure about that).
If that still does not help open the preferences for Docker (by clicking on the icon in the task bar) under the Advanced tab you can specify how many cores and how much memory docker is allowed to consume. I think the default is 2GB and you might want to change that to e.g. 4GB.
Related
I am dockerizing laravel (lumen) app locally on Mac computer.
docker-compose.yml:
version: "3.9"
services:
# LibreOffice Service
libreoffice:
image: lscr.io/linuxserver/libreoffice:latest
container_name: libreoffice
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/London
volumes:
- ./:/home
ports:
- "3000:3000"
restart: unless-stopped
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
As you see in yml file I am running my app in nginx container and everything works fine.
But when I try to run command:
docker exec libreoffice soffice --headless --invisible --convert-to pdf --outdir "home/public/tmp" "home/public/tmp/hi.docx"
in my application, it throws the following error:
sh: 1: docker: not found
After wasting days I thing that it is trying to find docker in nginx container not on my local computer. Means all other services I have defined in docker-compose.yml file can not be accessed in my application because my application = nginx container. But why? What should I do then? How should I create environment to access another services in my application?
MY BIG QUESTION
Why it is even running whole app in container? When I run app with nginx, then my app breaks the connection with my local environment and trying to find all other containers in nginx container. For example if I need to convert some files and for that convertation I need libreoffice service to run in background. And when I try to connect it with soffice --headless --invisible --convert-to pdf --outdir command it throws an error like:
sh: 1: soffice: not found
Because it is looking for soffice in nginx container not in my local docker at all. If that is the case then How can I even run my application with nginx? Do I need to run all other containers in nginx container? How is it possible?
After making some more research I have found that it is impossible to access to the container from another container and run some command inside.
Some solutions to that problem:
Use service's REST API to connect.
If your service doesn't have REST API to access and run it
Removing libreoffice service as container and installing it to php container with linux command in Dockerfile:
RUN apt-get update && apt-get install -y libreoffice
Command can be run remotely using ssh. Check this topic (I don't recommend)
I am using the Docker Engine running on WSL2 which is running on Windows 10 computer. My goal is to create a service using the Docker-compose that uses the php:fpm image and install the mysqli extension to it. Here is my docker-compose.yaml
version: "3"
services:
nginx:
image: "nginx"
restart: 'always'
ports:
- '3030:80'
volumes:
- ./src:/src
- ./config/site.conf:/etc/nginx/conf.d/default.conf
networks:
- code-network
php:
build:
context: .
dockerfile: Dockerfile
image: php:fpm
volumes:
- ./src:/src
networks:
- code-network
mariadb:
image: "mariadb:10.3.24"
restart: 'always'
volumes:
- "/var/lib/mysql/data:/data"
- "/var/lib/mysql/logs:/logs"
- /var/docker/mariadb/conf:/etc/mysql
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "T05CNCitk2020#"
MYSQL_USER: "user"
MYSQL_PASSWORD: "Heslo123"
networks:
- code-network
networks:
code-network:
driver: bridge
And here is my Dockerfile:
FROM php:fpm
RUN docker-php-ext-install mysqli
When I run the command docker-compose up --build which forces the container to rebuild. I ran into the following problem:
Building php
unable to prepare context: path "\\\\?\\\\\\wsl$\\Ubuntu-20.04\\home\\vendasky\\Projects\\sql-gui" not found
ERROR: Service 'php' failed to build : Build failed
I do not see the reason why the path should be wrong when all the files are located in the Linux subsystem. Any hints, how to solve this problem?
are you runnning this with docker desktop for windows?
If thats the case try enabling the Docker Compose V2 option under the experimental settings. This should fix your problem.
Docker is unable to find the path to that project, map your ubuntu correctly so it can easily locate the project, that should fix your issue.
I am using docker for my app that includes freeradius,nginx and php.
I want to use "program = "/usr/bin/php " this command in container freeradius but it is not working.
In freeradius container I want to run this command "/usr/bin/php" but it says command not found.
Can anyone help me in this ?
version: '3.2'
services:
freeradius:
image: "ronakzenexim/2stacks_freeradius:v1"
environment:
- RAD_DEBUG=yes
depends_on:
- mysql
- php
links:
- mysql
restart: always
networks:
- backend
php:
image: "ronakzenexim/phpfpm72_mycrypt"
restart: always
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- "./web:/var/www/html"
networks:
- backend
networks:
backend:
ipam:
config:
- subnet: 10.0.0.0/24
Create a extension of the freeradius docker image for example
FROM ronakzenexim/2stacks_freeradius:v1
# Now install php
RUN apk update && apk upgrade
RUN apk add php7 php7-fpm php7-opcache
In this container you can run php.
How can I recreate this?
Create install from Laravel 8 docs and Laravel Sail docs.
I use the sail up command, which works great. The command builds docker containers, connects them, and makes development as easy as we can imagine, especially for VSCode, and this works fine, but it's slow in development with WSL2. I mean commands like `sail npm run dev.' Any ideas on how to speed this up?
FYI: The same project that runs on the same machine is at least 10x faster. For more information, I ran tests on i9-10900X, 32 GB RAM on Docker Desktop for Windows 10.
docker-compose.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
mysql:
image: 'mysql:8.0'
ports:
- '${DB_PORT}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${REDIS_PORT}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
You should run docker from WSL2 if possible.
Install docker and WSL2.
Move your project to WSL by opening \\wsl$\ in explorer and navigating to your VM's home, in my case \\wsl$\Ubuntu-20.04\home\thomas
Run docker-compose up -d / sail up from the VM
I was going to explain this but just go here and read for yourself. This is what helped me. VSCode kinda yelled at me when I opened up a project in the default location and gave me this link. https://learn.microsoft.com/en-us/windows/wsl/compare-versions
Performance across OS file systems
We recommend against working across operating systems with your files,
unless you have a specific reason for doing so. For the fastest
performance speed, store your files in the WSL file system if you are
working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're
working in a Windows command line (PowerShell, Command Prompt), store
your files in the Windows file system.
For example, when storing your WSL project files:
Use the Linux file system root directory: \\wsl$\Ubuntu-18.04\home\<user name>\Project
Not the Windows file system root directory: C:\Users\<user name>\Project
All currently running distributions (wsl -l) are accessible via
network connection. To get there run a command [WIN+R] (keyboard
shortcut) or type in File Explorer address bar \\wsl$ to find
respective distribution names and access their root file systems.
You can also use windows commands inside WSL's Linux Terminal. Try
opening a Linux distribution (ie Ubuntu), be sure that you are in the
Linux home directory by entering this command: cd ~. Then open your
Linux file system in File Explorer by entering (don't forget the
period at the end): powershell.exe /c start .
I'm trying to deploy my dockerized application using docker-compose. I have an application service running with php-fpm and an nginx service running with the latest nginx image. Now I would like to build an image that can run my PHP application using Nginx. I'm not sure how to accomplish that. I have seen some images that are pre build for it, but nothing seemed promising.
Would the correct way to do it be to install nginx on a php based imaged and use that? I'm not sure.
version: "3"
services:
application:
networks:
- mynetwork
container_name: the-application
image: the-application:latest
build:
context: ./
dockerfile: ./docker/application.dockerfile
volumes:
- ./backend/:/backend
backend-server:
container_name: the-backend-server
image: the-backend-server:latest
build:
context: ./
dockerfile: ./docker/server.dockerfile
volumes:
- ./backend/:/backend
- ./configs/nginx/nginx.backend-prod.conf:/etc/nginx/conf.d/default.conf
ports:
- 80:80
networks:
- mynetwork
networks:
mynetwork: