Hi I am new to docker the only time i’ve been using docker is with Laravel Sail that comes with ready to use docker configuration.
I love the idea of using docker containers but have couple of doubts that i’m not able find the solution of, online. Please i’ll really appreciate if someone will explain or provide their guidance on this topic
My requirements are
Earlier i used to use xampp lets say xyz version that comes with xyz version of apache, mysql mariadb etc …which contains lets say 4 of my projects.
then i moved to some latest version xampp abc latest php , myql etc etc that again have 3 of my some project that uses latest tech version.
Now this kept on going NOW I HAVE SETS OF PROJECTS THAT USES SAME CONFIGURATIONS OR IN OTHER WORDS SHARES THE SAME SERVER REQUIRENMENTS.
As docker serves to this sole purpose i just dont know how to implement it.
if anyone can explain in simple language that would be really helpful.
Thanks in advance
You probably want to start from the beginning as you understood that this is what Docker is for, but this is exactly why all of the basic tutorials should explain the solution. I share my template of recommended links below, but in short: you use the same docker image and run multiple containers from that image. And you use a reverse proxy like Nginx Proxy or Traefik to be able to use a single port for multiple services instead of using virtual hosts. Of course you could use virtual hosts, but that is not what we do in containers. My tutorials linked below use Nginx Proxy but I use Traefik in production.
Recommended links to learn the basics and concepts:
thank you so much for guidance and sorry for late response i just saw it …
I was able to set up my projects using docker-desktop but the one with back end is causing trouble as i want to install some necessary packages on my php server/ php container using Dockerfile but the container is not able to access internet or access dns on the Build … i tried everything i could find almost going to give up lol.
below is my docker-compose.yml file
services:
php:
build:
context: .
dockerfile: Dockerfile # Ensure i have a Dockerfile in the same directory
image: webserver-php-7.2 # This will tag your built image
command: apache2-foreground # Ensures Apache runs in the foreground
volumes:
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini # Custom PHP config
# - ./src:/var/www/html # Mount project code (optional for shared PHP)
ports:
- "8081:80" # Map host port 8081 to container port 80
privileged: true # Run container as root
dns:
- 8.8.8.8
- 8.8.4.4
# network_mode: host # make sure when running network as host in order to solve the internet connecetion error at build , you must temporarily disable the below custom networks
networks:
- my-php7-network # Unique network for PHP 7.2
networks:
my-php7-network:
name: my-php7-network # ✅ Force exact network name
external: true
# build this docker image file as below to fix the dns internet connection issue before running the container with docker-compose up -d
# DOCKER_BUILDKIT=1 docker build --network=host --build-arg DNS_SERVER=8.8.8.8 -t webserver-php-7.2 .
and below is my Dockerfile
# Use the official PHP 7.2 image with Apache
FROM php:7.2-apache
# Set the working directory inside the container
WORKDIR /var/www/html
# below line is to solve internet connection error dns network error build the imabe with this command "DOCKER_BUILDKIT=1 docker build --network=host --build-arg DNS_SERVER=8.8.8.8 -t webserver-php-7.2 ."
ARG DNS_SERVER=8.8.8.8
# RUN apt-get update && apt-get install -y \ this line was causing dns error
# Update package list and install necessary dependencies
# Hardcode Debian repo IP to bypass DNS resolution issues
RUN echo 'Acquire::http::Pipeline-Depth "0"; Acquire::http::No-Cache "true"; Acquire::http::Timeout "60";' > /etc/apt/apt.conf.d/99fixbadnet && \
apt-get -o Acquire::ForceIPv4=true update && \
apt-get install -y
# Enable MySQL extensions
RUN docker-php-ext-enable pdo_mysql mysqli
lemme know if this issue feels familiar i tried eveything gpt told me to do lol