This repository goal is to create a docker container and compose: Centos, Apache, PHP and PDO DBLIB, MySQL
First, we create a file named docker-compose.yml. On that file we will define two services "web" and "db" The "web" service will use the Dockerfile for our Apache/PHP container.
- The "db" service will use the Dockerfile for our MySQL container.
- For the root user we are using the password "root". You may want to use a more secure password.
- We also use the port 3306 to access the MySQL server from the host machine. If you already have another instance of MySQL running, you may need to use a different port. (i.e. "4001:3306")
Open a terminal window, navigate to the folder with the docker-compose.yml file, and type the following command.
docker-compose up -d
After the containers have finished building, we can check the logs with the following command:
docker-compose logs
docker-compose stop
docker-compose down
Create Docker Image.
docker build -t <image_name> .
Create Docker Container.
docker run -tid -p 4000:80 --name=<container_name> -v /path_to/folder:/var/www/html <image_name>
Replace <container_name> with the name you want for the container, and <image_name> with the name of the image you specified on the Build command above.
Example.
docker run -tid -p 4000:80 --name=container_apache -v /path_to/folder:/var/www/html image_apache
Also change "/path_to/folder" with the actual location of your website's root folder on your local machine.
Open the http://localhost:4000/ url on your browser.
Open the http://localhost:4000/test.php url on your browser.