John Davidson

docker - Pictures not showing up on Dockerised PHP container

0 comments
Message:


Problem


I have Dockerised my PHP project, and for some reason the pictures from directory "icons" are not being displayed, but from "images" it's being shown. On console it shows up as 404 Not Found. I tried to move the picture from "icons" to "images" and then it shows up. Not really sure what could be the problem.


Working tree


????.
┣ ????mysql_data
┃ ┗ ????database_dump.sql
┣ ????src
┃ ┣ ????icons
┃ ┃ ┗ ????icon.png
┃ ┣ ????images
┃ ┃ ┗ ????photo.png
┃ ┗ ????index.php
┣ ????Dockerfile
┗ ????docker-compose.yml

Dockerfile


FROM php:8.0-apache
WORKDIR /var/www/html
RUN apt-get update -y && apt-get install -y libmariadb-dev
RUN docker-php-ext-install pdo_mysql
RUN a2enmod rewrite

docker-compose.yml


version: '3.9'

services:
php-env:
build: .
volumes:
- ./src:/var/www/html
ports:
- 9000:80

mysql_db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: amazon
volumes:
- mysql-data:/var/lib/mysql
- ./mysql_data/database_dump.sql:/docker-entrypoint-initdb.d/database_dump.sql

phpmyadmin:
image: phpmyadmin:latest
restart: always
ports:
- 9001:80
environment:
- PMA_ARBITRARY=1

volumes:
mysql-data:



My Answer:
are not showing up on the website when I access it through the Docker container.

_Solution_

1. Check the file paths: Make sure that the file paths in your PHP code are correct and pointing to the right directory where the images are stored. You may need to update the file paths to match the directory structure within the Docker container.

2. Check file permissions: Ensure that the images have the correct permissions set so that they can be accessed by the PHP application running in the Docker container. You can use the `chmod` command to change the permissions if needed.

3. Mount a volume: If the images are stored outside of the Docker container, you can mount a volume to make the images accessible to the container. Update your Docker run command to include a volume mount for the directory where the images are stored.

4. Restart the container: After making any changes, restart the Docker container to apply the updates and see if the images are now showing up on the website.

By following these steps, you should be able to resolve the issue of pictures not showing up on your Dockerised PHP container.

Rate this post

3 of 5 based on 7385 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us