Recently I tried to fabricate a Docker container in my Admidio-based web application, but I encountered to a tiny error:
When I open the localhost:8080 web page it displays the following message:
"The requested PDO driver mysql is not supported"
I modified several times the docker-compose.yaml file and the Dockerfile.
Here it is the docker-compose.yaml:
services:
php:
image: php:7.4-apache
ports:
- '8080:80'
volumes:
- /Applications/XAMPP/xamppfiles/htdocs/project:/var/www/html
environment:
- APACHE_RUN_USER=www-data
- APACHE_RUN_GROUP=www-data
- PHP_EXTENSION=pdo_mysql
depends_on:
- db
phpmyadmin:
image: phpmyadmin:latest
restart: always
ports:
- '8077:80'
environment:
- PMA_HOST=db
#- PMA_ARBITRARY=1
depends_on:
- db
db:
image: mysql:latest
ports:
- '5506:3306'
restart: always
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: TRUE
MYSQL_USER: user
MYSQL_PASSWORD: 1234567
MYSQL_ROOT_PASSWORD: 1234567
And the Dockerfile:
FROM php:7.4-apache
WORKDIR /var/www/html/
RUN a2enmod rewrite
RUN apt-get update && apt-get upgrade -y
RUN docker-php-ext-install mysqli pdo pdo_mysql
COPY . /var/www/html/
RUN chown www-data:www-data /var/www/html/
RUN chmod 755 /var/www/html/
# start Apache2 on image start
EXPOSE 80
# Use the official MySQL image as a base
FROM mysql:latest
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Set the default user for the MySQL image
USER mysql
# Set environment variables for the new user
ENV MYSQL_USER=external_user
ENV MYSQL_PASSWORD=password
ENV MYSQL_DATABASE=my_database
# Run the following commands to create the new user and grant them the necessary permissions
RUN mysql -u root -p -e "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';"
RUN mysql -u root -p -e "GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'%';"
RUN mysql -u root -p -e "FLUSH PRIVILEGES;"
# Expose port 3306 to allow connections to the database
EXPOSE 3306
# Start the MySQL server when the container is run
CMD ["mysqld"]
Thank you!
You need to sign in to view this answers