Jump to content
gebeer

docker image for PW with nginx proxy and php-fpm

Recommended Posts

Hello everyone,

I've been fiddling around a lot lately with docker containers for my local development on a linux machine. Tried many different options, also readily available processwire images and tutorials from the forum. But never got it right. Mainly because of permission issues with docker volumes. That is a tricky part on linux machines whereas on OSX it doesn't seem to be an issue.

Then I discovered http://www.wordpressdocker.com/. And the setup with nginx as a proxy that routes requests to separate containers with the actual site install appealed to me. The whole thing sits on top of alpine linux containers which are really lightweight. So I decided to give it a try.
And, first time since experimenting with docker, I got a running PW install. Rewriting was not working until I adjusted the nginx config. Now I have a fairly complex PW site running in a container. Everything is working, image upload/editing etc.

So I'm really exited, especially since the dev site is now blazing fast compared to my old vagrant virtualbox vm setup.

Honestly, I don't really understand everything that is happening behind the scene. But I managed to adjust the original files and build a new image that works with PW and doesn't have all the WP stuff.
The nginx config I took from https://github.com/elasticweb/nginx-configs/blob/master/configs/processwire-2.conf
Not sure if it covers everything for PW3 as well. I would very much appreciate if someone who is more in the know than me could take a look.

All files for building the docker image are here https://github.com/gebeer/alpine-php-processwire
A working image here: https://hub.docker.com/r/gebeer/alpine-php-processwire/

Documentation is kind of lacking. I took over quite a lot from the original project. But following the github README and the original documentation should get people started who have a little experience with docker already.

If someone needs a more in depth step by step tutorial for setting things up, let me know and I'll put something together.

  • Like 10

Share this post


Link to post
Share on other sites
11 hours ago, gebeer said:

So I'm really exited, especially since the dev site is now blazing fast compared to my old vagrant virtualbox vm setup.

That's great to hear! It makes me want to give it a go just to see how it compares with my vagrant/vb box config. More speed = more better lol.

Share this post


Link to post
Share on other sites
On 1/23/2017 at 0:35 PM, gebeer said:

If someone needs a more in depth step by step tutorial for setting things up, let me know and I'll put something together.

Would be great!

Share this post


Link to post
Share on other sites

@arjen I updated the README at https://github.com/gebeer/alpine-php-processwire

Hopefully this makes things more clear.

And here is a great resource for some basic docker commands (listing/removing of images, containers and volumes). I needed them a lot when experimenting...

Please let me know how it is going for you.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks, will try it this weekend!

Share this post


Link to post
Share on other sites

Update:

Working with this setup I found that installing modules with the installer from the admin did not work because php-zip module was not installed.

I fixed this and pushed the new image and Dockerfile to dockerhub and github.

  • Like 1

Share this post


Link to post
Share on other sites

THis is awesome, thanks so much for sharing.

I'm just getting into docker for my local pw development (on windows) and this will be fantastic.

Not knowing too much about docker, is there a way to use docker compose to simplify the commands that are needed to get this running?

From what I understand, compose allows you to put all those setup commands for all 3 containers into a config file that can be run with one simple command.

Could this be used as a launching board to make something like wocker but for processwire?

  • Like 1

Share this post


Link to post
Share on other sites

@rastographics you're welcome.

I didn't know much about docker either, before I put this together. Took me 2 days to get to know basic concepts and find existing images that I could base mine on.

Read about docker-compose, too. But I decided to first learn proper use of docker with native docker utilities before using some wrapper around it. Makes me feel more confident when it comes to solving issues.

Also, when you have setup your containers once with docker run ..., they are very easy to handle.
Example: you have set up 3 containers following the README.md with names nginx, mariadb, example_com
To stop them, just run: docker stop nginx mariadb example_com
Next time you want to work on example_com: docker start nginx mariadb example_com
Then you setup a fourth container with a new dev project with docker run --name example2_com ...
To work on that project. you do: docker start nginx mariadb example2_com

Its that easy. So I have no need for docker-compose.

Just had a very quick look at wocker and it looks interesting. With my system I can start up a new project within less than 5 minutes. And thats quick enough for me ;)

Share this post


Link to post
Share on other sites

@gebeer I'm having some problems getting this to work as per the instructions in the README...

1. Is there a reason that there is a static IP addressed used with the mariadb container? The example has 

172.17.0.1:3306:3306

for the port mapping on that container, but I `cannot assign requested address` when trying to run the command as written...

 

2. I get an error because the nginx and processwire containers BOTH are mapped to host port 80...wouldn't I just map the nginx container to host port 80? And where is nginx setup to point to the processwire container?

 

Thanks

Share this post


Link to post
Share on other sites

Running Docker 1.13.1-beta42 on Windows 10 Pro 64-bit, using the native Hyper-V based Linux containers. (not virtualbox).

I've gotten other processwire images (specifically https://github.com/antonioandrade/docker-processwire-nginx) to run successfully on my setup.

I would rather use your image than the one above because that one is on php 5 and also it installs old version of pw automatically (I just want to copy in my existing site instead).

Share this post


Link to post
Share on other sites

OK after 2 days I got the basic stack functional...havent attempted loading of processwire yet.

The key for me was I had to look at the readme of https://hub.docker.com/r/etopian/nginx-proxy/ to see what was going on and how the reverse proxy feature works with that image.

I hope to post my final configuration for this when I'm done, for any other Windows devs who want to be able to develop multiple PW sites simultaneously on their PC. (No need to take turns starting and stopping containers).

Thanks for your work gebeer.

  • Like 1

Share this post


Link to post
Share on other sites

For any Windows developers interested in an easy way to get going with Docker and Processwire that includes local debugging...

https://github.com/rastographics/pwocker

  • Local debugging in your IDE with Xdebug pre-configured. (Also includes working launch.json for you VS Code users )
  • Use *.localtest.me hostnames for each site you are developing (no editing of hosts file)
  • Simple configuration...copy 2 files into your project, edit a couple variables in those files, and run 1 command per project.
  • Tested with Docker 1.13.1-beta42 on Windows 10 Pro 64-bit.

I didn't know much at all about Docker, nginx, or xdebug before doing this, so I pulled much info from gebeer's work and many others who have put Docker/PHP/xdebug stuff out in the community. And it may not be the best setup ever, but it finally gives me what I needed for doing PW work on Windows in a true Linux stack with IDE debugging.

  • Like 8

Share this post


Link to post
Share on other sites

Update: working with this setup for a few months, I had quite a few permission related issues which were frustrating.

So I decided to do some more research on existing docker projects that are well maintained and bring the features I need.

Finally I found http://laradock.io/. I've been using it for  3 months now and I am really happy with it. Very flexible and well maintained set of docker containers.

I'm totally happy and can recommend it to devs who are interested in this topic.

 

  • Like 7

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By anttila
      I have a new server and wanted to use nginx. However, I have two ProcessWire websites which does not let me do anything. I'll get this error every time when I try to change something and sometimes when logging in. Deleted all caches already from ProcessWire and browser. This also happens after installing new ProcessWire and all directories were owned by www-data.
      I also have two working websites without any problems and all these four uses same kind of setting on nginx config. I don't understand why some of those working fine and some not.
      Running Debian 10, MariaDB 10.3.22, PHP 7.4, nginx 1.14.2
      This request was aborted because it appears to be forged. #0 /sites/clients/clientname/wire/modules/Process/ProcessPageTrash.module(49): ProcessWire\SessionCSRF->validate() #1 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\ProcessPageTrash->___execute() #2 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #3 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #4 /sites/clients/clientname/wire/core/ProcessController.php(337): ProcessWire\Wire->__call() #5 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\ProcessController->___execute() #6 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #7 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #8 /sites/clients/clientname/wire/core/admin.php(150): ProcessWire\Wire->__call() #9 /sites/clients/clientname/wire/modules/AdminTheme/AdminThemeDefault/controller.php(13): require('/sites/clients/...') #10 /sites/clients/clientname/site/templates/admin.php(15): require('/sites/clients/...') #11 /sites/clients/clientname/wire/core/TemplateFile.php(318): require('/sites/clients/...') #12 /sites/clients/clientname/wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #13 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #14 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #15 /sites/clients/clientname/wire/modules/PageRender.module(536): ProcessWire\Wire->__call() #16 /sites/clients/clientname/wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage() #17 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #18 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #19 /sites/clients/clientname/wire/core/WireHooks.php(924): ProcessWire\Wire->__call() #20 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #21 /sites/clients/clientname/wire/modules/Process/ProcessPageView.module(213): ProcessWire\Wire->__call() #22 /sites/clients/clientname/wire/core/Wire.php(383): ProcessWire\ProcessPageView->___execute() #23 /sites/clients/clientname/wire/core/WireHooks.php(823): ProcessWire\Wire->_callMethod() #24 /sites/clients/clientname/wire/core/Wire.php(450): ProcessWire\WireHooks->runHooks() #25 /sites/clients/clientname/index.php(55): ProcessWire\Wire->__call() #26 {main}  
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By rushy
      Hi all
      Continuing my first project where I am creating and manipulating stuff from the frontend. Till now I've always added things like images from the backend, but in this project I need to add and move images from a frontend control. This is a photo album where images are stored in albums, each album being a page containing a Pageimages array in the usual way. So what I want to know is how do I move an image from one album (page) to another in the frontend? I just need some guidance on how to approach this.  I suppose I need to do a copy and delete - but how do I copy an image or images from one page to another? What function should I use to create a new image on an existing page? I include a code snippet from the server side of my delete image request and it works fine. I'd like to implement something similar for a move and upload new image request. 
      Many thanks for any help. Paul 
      <?php namespace ProcessWire; // sanitize inputs as 1-line text $action = $sanitizer->text($input->post('action')); $instr = $sanitizer->text($input->post('input')); $sel = $input->post('selected'); // Expect JSON for image selected image list $selected = json_decode($sel); $nosel = count($selected); $response = array(); // for building JSON response switch($action) { // delete selected images case 'delete': $out = "<p>Deleted $nosel image(s)</p>"; foreach($selected as $item){ $album = $pages->get($item->album); $album->of(false); $out .= "<p>Image {$item->file} from album {$album->title}</p>"; $album->images->delete($item->file); $album->of(true); } $out .= saveUpdatedAlbums($pages, $selected); // add the response message for the delete $response['message'] = $out; break; ...... // save any album that had an image deleted function saveUpdatedAlbums($pages, $selected) { $cur = ''; $out = ''; foreach($selected as $item){ $album = $pages->get($item->album); if($album->id != $cur) { $album->of(false); $album->save('images'); $album->of(true); $cur = $album->id; $out .= "<p>Updated album {$pages->get($cur)->title}</p>"; } } return $out; }  
       
       
    • By Robin S
      Inspired by a recent question.
      Image Crop Ratios
      Allows preset aspect ratios to be defined per image field for the ProcessWire image crop tool.
      The module adds a select dropdown to the crop tool. Choose an aspect ratio and the crop area will be fixed to that ratio.
      Screencast

      Installation
      Install the Image Crop Ratios module.
      Configuration
      Default aspect ratios for all image fields can be defined in the module config. Aspect ratios for specific image fields can be defined on the Input tab of the field settings. You can override the ratio settings in template context if needed. Insert a hyphen as the first item in the ratio settings unless you want to force a ratio to be applied to the crop tool. The hyphen represents a blank option that allows a free crop area to be drawn. Usage
      Click the "Crop" link on the details view of an image thumbnail. Click the "Crop" icon at the top of the editor window. Choose an option from the "Ratio" select dropdown.  
      https://github.com/Toutouwai/ImageCropRatios
      https://modules.processwire.com/modules/image-crop-ratios/
    • By rushy
      Bit of a newbie type question, even though I've been using PW for quite a while, I've not had to manipulate assets from the front end before.  I now have a need to update image properties from the front end and I'm trying to update an image description and tags when clicking on a link. I get the selected image and for example I can delete it with the code below. But I am missing some basic understanding when updating image description field as nothing happens, no errors but the description field remains empty. Any idea what steps I am missing? Many thanks. 
      // how to update image description? $al = $pages->get($album); $pgfile = $al->images->getFile($file); $al->of(false); $pgfile->description = "Test description"; $al->save(); // to delete an image - this works $al->of(false); $al->images->delete($file); $al->save();  
×
×
  • Create New...