What is Docker? Docker is a software platform that allows you to package, distribute, and run applications in an independent unit called a container. This container includes everything that is needed by the application, such as code, Runtime, and Library, ensuring consistent execution in different environments.
How can this be useful? There are many possibilities for using a docker container. You can use it to test for example. If you have a website that runs on PHP 8.1 and wants to make sure that switching to PHP 8.3 does not damage anything, you can make a container based on PHP 8.3 and fully test your application there before conducting a switch on the main website. Other options include distributing your application to your customers as a container or using a container for web hosting if your web hosting provider supports this option.
In this article we will explain how you can package your Phprunner application as a docker container.
Desktop Docker installation
As a first step, you need to install a desktop docker on your local computer. Simply download from the official website and install all the default settings.
After the desktop docker is installed, launched. The two main parts we will do Picture And Receptacle.
Docker image is only a read template that contains everything needed to run applications, including application codes, system tools, and libraries. The docker container is the instance running from the docker image considers the picture as a blueprint and a container as a building built from the blueprint.
Project structure
Create a new folder for our Docker project, C: \ Project \ Docker. This is the default docker project. SRC Folder needs to be made manually and this is where all our PHP files will be saved. Fortunately, we don’t need to make other files manually, desktop docker can help us make it.
Init Docker
Start by opening the terminal (click the terminal icon in the lower right corner). First, turn to your project folder and then run Init Docker rule.
Docker will ask a few questions about what you want to make. Select the Apache+PHP web application. You can use the top and bottom keyboard keys to change your choice. Press Enter to make a choice.
For all other questions, leave the default option. Docker will make an image for you, based on your choice. On Picture Your tab will now see a new picture. Docker will also tell you that now you need to run Docker arranged -build Commands to build and launch your container.
Dockerfile
This is how the initials Dockerfile seen. I just deleted some additional comments for short. Let’s try to make a container and run it.
Wake up and run first
Without making any changes Dockerfile We returned to the terminal and carried out the recommended build command:
The first building will take about one minute and successively will be a little faster. DCker builds and starts our container. You can see the status of the container on the container tab. You can see that our new container has run out and runs.
Which means we can now open a web browser and type the following url: http: // localhost: 9000. This is what you should have seen:
Good news: Our container is actually running.
Bad News: Mysqli extension does not exist and we cannot connect to MySQL.
Installing the MySqli extension
Google search quickly to “PHP Docker Install Mysqli” points to us to solutions and we modify us Dockerfile In any text editor that adds rows 7 and 8.
Now we stop the container, run the build command again and after finishing we refresh our browser window. This brings us one step further but we are not enough.
Although this error is not too descriptive, we can guess that our application cannot be connected to MySQL. We use “localhost” as the address of the MySQL server which in terms of the container refers to the container itself. We need to find a way to connect to MySQL in a host which is our local computer that runs a desktop docker. Another fast google search for “docker connect to host from container” points us to host.docker.Intternal what we need to use is not localhost When connecting to MySQL.
We proceed to Phprunner, create a new server database connection on the ‘Output Directory’ screen and change the MySQL server address as follows:
And one more try
1. Stop the container
2. Build a phprunner project (make sure the new connection is selected)
3. Copy all files from the output phprunner to C: \ Project \ Docker \ SRC folder
4. Execution Docker arranged -build ordered once more.
5. Refresh Browser’s Window
It goes!
Additional notes. You can make your container connected to any database. This can be a database that is part of the same container (though not recommended), or a database that runs in another container or any external database server. All you need to do is direct the database connection to the database of your choice.
Game Center
Game News
Review Film
Rumus Matematika
Anime Batch
Berita Terkini
Berita Terkini
Berita Terkini
Berita Terkini
review anime