Skip to content

Customized images based on PHP/XDEBUG for web development.

Notifications You must be signed in to change notification settings

jesuserro/docker

Repository files navigation

My Docker Garden

Simple examples of using Docker. Creation of containers with PHP 7/8 and XDebug. It is made from:

These Dockerfiles are based on the official images, but they have been modified to install XDebug and other extensions.

Installation

mkdir ~/proyectos && cd ~/proyectos
git clone https://github.com/jesuserro/docker.git

File Structure

📦home
 ┣ 📂jesus
 ┃ ┗ 📂proyectos
 ┃ ┃ ┗ 📂docker
 ┃ ┃ ┗ 📂project-1
 ┃ ┃ ┗ 📂ofertas
 ┃ ┃ ┗ 📂nges

Usage

Run containers

cd ~/proyectos/docker

# Run/Launch container for php 7.0
docker compose up
docker-compose docker-compose.dev.yml up

# Run/Launch all containers for php 7.0 and php 8
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up

In your browser

Regenerating containers

# Create new image called "my-php-image70" from existing "Dockerfile.70"
docker build -t my-php-image70 -f Dockerfile.70 .
docker build -t my-php-image81 -f Dockerfile.81 .

# Run new container instance called "my-php-container70" based on existing image "my-php-image70"
docker run -d -p 8070:80 --name my-php-container70 my-php-image70 -v /home/jesus/proyectos:/var/www/html
docker run -d -p 8081:80 --name my-php-container81 my-php-image81 -v /home/jesus/proyectos:/var/www/html

Other commands

# Start terminal session inside the "my-php-container70" container
docker exec -it my-php-container70 /bin/bash

# Show container logs
docker logs my-php-container70

# Stopping a container
docker stop my-php-container70

# Removing all docker containers  
docker container rm -f $(docker container ls -aq)

# Removing all docker images  
docker rmi $(docker images -q)

# Removing all in 1 sentence
docker container rm -f $(docker container ls -aq) && docker rmi $(docker images -q)

# Full remove
docker system prune -a

# Borrado total de la caché
docker builder prune -a

XDEBUG

In your WSL2 terminal, run this command to get your IP address:

ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
  # Returning: 172.20.28.159

XDebug 2.5.5/PHP 7.0

So put it at the xdebug.ini file:

xdebug.remote_host = 172.20.28.159

XDebug 3/PHP 8+

No need IP definition, so put it at the xdebug.ini file:

xdebug.remote_host=host.docker.internal

and in the docker-compose.dev.yml file, beware of these environment configurations:

  environment:
    XDEBUG_MODE: develop,debug
    XDEBUG_CONFIG:
      client_host=host.docker.internal
      start_with_request=yes

It might be breaking the breakpoint debug.

VSCODE

If the IP is correct, you should see the Call Stack requests in the Debug Pane at VSCODE. Now, in the launch.json in your VSCODE project, add this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug on Docker",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html/docker/": "${workspaceFolder}/"
            },
            "log": true,
            "ignore": [
                "**/vendor/**/*.php"
            ]
        }
    ]
}

At Debug Console we'll see:

Listening on { address: '::', family: 'IPv6', port: 9003 }

Php Executable

# Getting executable from the container
docker cp php70-apache:/usr/local/bin/php ./var/bin/php
# In VSCODE settings.json
"php.executablePath": "./var/bin/php"

# Executable from your local LAMP
which php
# In VSCODE settings.json
"php.executablePath": "/usr/bin/php"

Tutoriales

DOCKER De NOVATO a PRO! (CURSO COMPLETO EN ESPAÑOL)

DOCKER De NOVATO a PRO! (CURSO COMPLETO EN ESPAÑOL)

Aprende Docker en 14 minutos 🐳

Aprende Docker en 14 minutos 🐳

Otros enlaces de interés

De PHP 5.3 a PHP 8.2

Docker containers are useful for testing your code in different PHP versions. This video shows how to use Docker to test your code in PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, and 8.1. De PHP 5.3 a PHP 8.2

Interesting Dockerfiles

About

Customized images based on PHP/XDEBUG for web development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published