Execution of the PHPrunner app as a docker container – Xlinesoft Blog


What is Docker? Docker is a software platform that allows you to pack, distribute and execute applications in autonomous units called containers. These containers include everything that the application needs, such as the code, the execution time and the libraries, guaranteeing constant execution in different environments.

How can this be useful? There are many possible uses of Docker containers. You can use them to try, for example. If you have a website that works with PHP 8.1 and you want to ensure -you change to PHP 8.3 Do not break anything, you can create a container based on PHP 8.3 and completely try your application before making a change on the main website. Other options include distributing your application to your customers as a container or using containers for web hosting if the web hosting provider admits this option.

In this article we will explain how you can pack your PHPrunner app as a Docker container.

Docker desktop installation

As a first step, you must install Docker Desktop on the local computer. You only need to download it from the official website and install it by maintaining all default configurations.

Once Docker Desktop has been installed, throws it. Two main sections we will work with are Pictures and Containers.

A docker image is a only reading template that contains everything you need to execute an application, including the code of the application, the tools of the system and the libraries. A docker container is an instance that works with an image of Docker, think of an image as a model and a container like the building built from this model.

Project structure

Create a new folder for our DOCKER project, that is, C: \ Project \ Docker. The following is how the Docker project is seen by default. SRC The folder must be created manually and this is where all our PHP files will be stored. Luckily, we don’t need to create the rest of the files manually, Docker Desktop can help us create them.

Docker Init

Start by opening a terminal (click the terminal icon in the lower right corner). First change in your project folder and then run Docker Init Order.

Docker will ask you some questions about what you want to create. Select APACHE+PHP Web App. You can use the keyboard keys up and down to change your selection. Press ENTER to choose.

For the rest of the questions, leave the default options. Docker will create an image based on your selection. Over Pictures Tab now you will see a new picture. Docker will also tell you now you have to run Docker Compon Order to create and launch your container.

Dockerfile

This is like the initial dockerfile Look. I just got some additional comments for brevity. We try to create a container and run it.

Build and first race

Without making any changes to dockerfile We return to the terminal and execute the suggested creation order:

The first creation will take about a minute and consecutive it will be a little faster. Dcker makes the creation and starts our container. You can see the status of the container in the Contain tab. You can see that our new container is in operation.

What it means that we can now open a web browser and write to the following URL: http: // localhost: 9000. This is what you are supposed to see:

Good news: Our container works in fact.
Bad News: Mysqli extension is missing and we cannot connect to MySQL.

Installation of the MySQLI extension

Google Fast Google “Docker PHP Install MySQLI” points to the solution and modify our dockerfile To any text publisher that adds lines 7 and 8.

Now we stop the container, we run the creation order again and once finished, update the browser window. This takes us another step, but we are not yet there.

Although this error is not very descriptive, we can guess that our application cannot be connected to MySQL. We use “localhost” as an address of the MySQL server, which in the case of the container refers to the container. We need to find a way to connect to MySQL to the host, which is our local computer that executes Docker Desktop. Another quick search for Google for “Docker Connect in Host of Lamb host.docker.internal that we must use instead of localhost while connecting to MySQL.

Continue to PhPrunner, we create a new server database connection to the “Exit Directory” screen and change the mySQL server address as follows:

And one more attempt

1. Stop the container
2. Create Phprunner Project (Ensure -s that a new connection has been selected)
3. Copy all the files in the PHPrunner output folder at C: \ Projects \ Docker \ SRC
4. Execute Docker Compon Order once again.
5. Update the browser window

It works!

Additional notes. You can make your container connect to any database. It can be a database that is part of the same container (although not recommended), or a database that is executed in another container or any external database server. All you have to do is point the connection of the database to your database you choose.



Technology

Motivation

News

Pendidikan

Pendidikan

Download Anime

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post