How to use docker (kitematic) like xampp works? - php

I'm trying to learn how to use docker (I have to use kitematic because I'm not able to use commands, so everything I do I do it in kitematic, so please don't tell me about commands). I'm using docker toolkit for windows 10.
What I'm trying to achieve:
I want something like xampp. I mean: creating/managing databases with phpmyadmin and a folder where I can store my projects folder (something like htdocs in xampp) so I can run and test my php scripts. Even if I have to use (for example) wordpress, I want to be able to browse the wordpress root, navigate files, edit them, etc. But wordpress is only one of the things I need to test, I also need to run plain php pages. I also want 2 php containers I can run on my choice (example: if I want to test something with php 7.4 I run a container, if I want to test with php 5.6 I run another).
I tried to create apache containers (httpd), php containers, mysql containers, etc. But maybe there's something I don't get.
If I start the mysql container I have the mysql engine but I can't manage databases. So I start the phpmyadmin container but it runs on its own, not linked to mysql (if I start the phpmyadmin container but not the mysql and php ones, it works too... why?) and I can't access it because I don't know what credentials I should use.
If I start the apache container I don't see any way to browse files so I can store project files.
Only the mysql container tells me how to configure it (setting the root password). Other containers just don't. The php container starts and close immediately.

Related

How to setup web application created in PHP (with Xampp)?

I have created an administrative system for libraries which basically lets you register books, users, borrowings and all kind of stuff that happens in a library. To code and test it, I used XAMPP, in my own PC, using Apache PHP and MySQL to structure and develop the application.
It works, and has a very complete and efficient set of functions and utilities, that is why I plan to implement it in my school's library, that for years has been using Microsoft Excel as a tool to organize all the books and students.
The thing is: I don't understand how to setup this app as a local web application. The idea is to install the folders and files in the library computer so it can control the system locally and through a browser (using localhost to access the PHP application).
I know it is possible to simply install XAMPP manually and copy the folder to htdocs and then use it normally, but I want to eliminate the manual part, and have some sort of setup that lets any person install the app without having to understand how Apache or MySQL works.
Does anybody know what could I do? I have though of creating a series of batch files (the library PC uses Windows) and move folders, create shortcuts, etc. using normal cmd commands. It would be a better alternative, but still the user would need to go through XAMPP (or some other service) setup prompts.
Thanks very much
you can create a bash file to automate this process.

Dockerizing existing zend web app project

I have a web based application using Zend framework running on LAMPP server and MYSQL which I would like to Dockerize. Essentially, I would like to do the following:
Create a docker file that would be my docker container for the web application
Be able to pass in a configuration to this docker file so that I can build the docker image either for my local code base or pull from master branch
Any suggestions on how do I get started?
As a general best practice you should only have one service - daemon - in each container. So in your case, when you have apache and mysql, you should think about two containers. For running them at the same time you can either put together a simple bash script, or have a look at docker-compose.
The Dockerfile for the apache container would either have a volume mapped to your "live" code on your disk, or it would contain the code inside. To do the former, you would use the VOLUME declaration in the Dockerfile, and then "-v" parameter when running it (or "volumes" declaration in docker-compose.yml). To do the latter, you would use the ADD instruction in Dockerfile.
Now if you want some kind of switch between these two, I would suggest creating three Dockerfiles, such as Dockerfile.parent, Dockerfile.app, Dockerfile.live - where:
the parent contains all your dependencies
the other two use "FROM parent"
app uses the ADD instruction and therefore contains the code inside
live uses the volume

How to quickly switch Docker containers on production?

Imagine that i had created service for uploading kittens pictures and use Docker container on production.
To do it I created Docker image with PHP 5.5 service, mounted "upload" folder of my app from real OS and also mounted folder with source code.
After some time I decided to improve my app, changed source code and now it requires different env from existed in Docker.
For example, now I need PHP 5.6 instead of PHP 5.5
So when I want to change source code of my app, I can do it by switching mounted source code folder with symlinks (or cannot, because Docker will keep socket? If so, how to switch source code? Should I do it right in container without mounting?).
But how can I quickly switch Docker container after switching source code?
Fastest way would be to exec a shell session in the container, update the environment, restart the php service. As you have mounted the source code, no need to switch.
Best way would be to create a docker image with required environment and stop previous container then run the new image mounting appropriate directories.

Dockerized PHP Application Architecture Best Practices

I'm pretty new do Docker. I played a lot with Docker in my development environment but I tried to deploy real app only once.
I've read tons of documentations and watched dozes of videos but still have a lot of questions.
I do understand that Docker is just a tool that can be used in so many different ways, but now I'm trying to find the best way to develop and deploy web apps.
I'll use real PHP App case to make my question more concrete and practical.
To keep it simple let's assume I'm building a very simple PHP App so I'll need:
Web Server (nginx)
PHP Interpreter (php-fpm or hhvm)
Persistent storage for SESSIONs
The best example/tutorial I could find was this one year old post. Dylan proposes this kind of structure:
He use Data Only container for the whole PHP project files and logs and docker-compose to run all this images with proper links. In development env I'll mount a host directory as a data volume and for production I'll copy files directly to Data Only Images and deploy.
This is understandable. I do want to share data across nginx and php-fpm. nginx needs access to static files (.img, .css, .js...) and php-fpm need access to PHP files. And both services are separated so can be updated/changed independently.
Data only container shares a data volume that is linked to nginx and php-fpm by --volumes-from option.
But as I understand - there's a problem with Data Only containers and -v flag.
Official Docker Documentation says that data volume is specially-designated directory to persist data! It is said that
Data volumes persist even if the container itself is deleted.
So this solution is great for data I do not want to loose like Session files, DB storage, logs etc.. But not for my code files, right? I do want to change my code files. I want to deploy changes without rebuilding nginx and php-fpm images.
Another problem is when I tried this approach I could not deploy code changes until I stopped all running containers, removed them and their images and rebuild them entirely. Just rebuilding and deploying Data Only images did nothing!
I've seen some other implementations when data is stored directly in Interpreter container, but it's not an option because I need nginx to have access to these files also.
The question is what is the best practices on where to put my project code files and how to deploying changes for this kind of app?
Thanks.
Right, don't use a data volume for your code. docker-compose makes a point to re-use old volumes (so you don't lose data), so you'd always be stuck with old code.
Use a COPY directive to add the static resources in the nginx Dockerfile and a COPY in the application (phpfpm) Dockerfile to add the code. In dev you can use a host volume so that you don't have to restart containers to see your code changes (assuming the web server supports picking up changes).

PHP Application Installer

I have a php application, I want to install it on another PC so they can use it but i want an automatic way that will install XAMP & copy my application files to that PC without me doing all these is there any installer I can use?
I need it to install XAMP automatically
Need it to copy files from installer & paste in the xamp folder.
Create a desktop icon so they can launch & start using it.
It will open browser, will run the apache in the background. and execute the php
anything to resolve?
Popular CMSs like Wordpress do installation just by copying the files and launching the SQL scripts for the database - create database and fill test data if needed. Which is fine.
The real question is how do you install XAMPP in the first place. Because for that it's not enough just to copy files. And even if you do manage to install XAMPP, you have to automatically start the Apache and MySQL. Don't say that it's impossible, but I think you should look for an easier way and deal with that another PC owners.

Categories