This is my docker-compose.yml so far:
wordpress:
image: wordpress
links:
- db:mysql
ports:
- 8080:80
net: "bridge"
dns:
- 8.8.8.8
- 4.4.4.4
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: biersaufen
Is there a way to directly install wordpress plugins? (Directly means that i can install it via the docker-compose.yml)
Yes, you can, but not directly via the docker-compose file.
You need to use the "build" section of the docker compose and have a Dockerfile that will install the modules for you. That way when you run docker-compose on your directory, it will first build the image with the plugins and use that image to start the stack.
Related
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 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.
I'm new to docker. I have a WordPress stack for local dev that implements wp-cli via a different container. The WP container has PHP 7.2.4, but the wp-cli container appears to have php 5.6.27.
What's the best approach to updating php for wp-cli?
remove wp-cli container, install wp-cli, save as a new container
use a different container for wp-cli
update php inside the existing container
?
snippets from my docker-compose file:
wordpress:
container_name: wordpress
depends_on:
- db
image: jburger/wordpress-xdebug
volumes:
- "./public:/var/www/html"
wpcli:
command: "--info"
container_name: wpcli
entrypoint: wp
image: tatemz/wp-cli
links:
- db:mysql
volumes:
You're pulling in an image which hasn't been freshly built/pushed in a year.
The DockerFile itself of these images is exactly what you need. If you clone the original repo into a folder, set the build param in your docker-compose file to that folder, and then run docker-compose build, you'll have a fresh image.
The ideal setup is to actually have a 'workspace' container, which contains all of the tools needed to interact with your project, for a reference of what that looks like, see laradock (it can be a bit overwhelming).
I want to make a project in PHP (Symfony) and MongoDB.
I created the file docker-compose.yml:
web_server:
build: .
ports:
- 5000:5000
links:
- mongo
mongo:
image: mongo:3.0
container_name: mongo
command: mongod --smallfiles
expose:
- 27017
And I try to run Docker Compose in PHP Storm but I recived:
Removing old containers...
(Re)building services...
mongo uses an image, skipping
Building web_server
Cannot locate specified Dockerfile: Dockerfile
Starting...
Building web_server
Cannot locate specified Dockerfile: Dockerfile
No containers created for service: web_server
No containers created for service: mongo
Failed to deploy 'Compose: docker-compose.yml': Some services/containers not started
I don't know what I should do, what should contain Dockerfile, what create containers.
Thanks!
Done!
I use Dockerfile from https://github.com/lepiaf/docker-symfony2 (with all files) and previously docker-compose.yml.
Thanks!
I want to play around with docker so I created my own 2 container, nginx and php. Both container are build successfully and are published on docker hub. After that I created a fig.yml in my projects folder. If I run fig up -d in my terminal, then I got the following error:
Recreating playground_php_1...
Cannot start container e087111c...: [8] System error: no such file or directory
Any ideas how I can fix this problem?
Here is my fig.yml:
web:
image: mc388/docker-nginx:latest
ports:
- "80:80"
- "443:443"
links:
- php
volumes:
- ./logs/nginx:/var/log/nginx
volumes_from:
- php
php:
image: mc388/docker-php:latest
volumes:
- .:/var/www/
And here are the links to the config of both docker containers:
https://github.com/mc388/docker-nginx
https://github.com/mc388/docker-php
The underlying php:fpm image has the following line in the Dockerfile:
WORKDIR /var/www/html
You then delete this directory, which breaks the default CMD command as it uses WORKDIR as its base.
I don't know much about PHP and this Docker image, but it's worth reading the documentation and looking at any examples you can find on how to use it; deleting a directory feels like you're working against the image.