Docker Community Forums

Share and learn in the Docker community.

File_exists() not working

  • OS Version/build
  • App version

I am trying to integrate an image library into my docker based project. In one of the supplied source files I see file exists() is failing. I have a directory on the host that I am using to debug the code (see path below). I am starting to think that my php code can’t see my directory on the host.
The code uses file_exists() to see if a certain module is at /opt/docker-substantiator/app/application/views/list.php. it is a pretty straightforward function call and I think this must be a Docker induced failure. I called getcwd and it is /app. Any idea why I can’t see if this file exist?. Remember, my php is running in a container.

Hi,

You dont give enough information (Dockerfile, how the container is created, what volum does it have…) to get a valid reponse.
The only thing I can tell you for now is : containers do not share the host “/” directory so depending on how you set things the file might not be available or at an other place.

Seb

Sorry about that. Here is what I think is the docker-compose.
version: ‘2’

services:

apache:
image: bitnami/apache:latest
restart: unless-stopped
ports:
- 80:8080
volumes:
- ./apache/app.conf:/vhosts/app.conf:ro
- ./app:/app
networks:
- net

mysql:
container_name: “mysql”
restart: unless-stopped
image: mysql:5.6
environment:
- MYSQL_DATABASE
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
- MYSQL_USER
volumes:
- data:/var/lib/mysql
- ./mysql/mysql.sql:/docker-entrypoint-initdb.d/mysql.sql
ports:
- “3306:3306”
networks:
- net

phpmyadmin:
container_name: phpmyadmin
restart: unless-stopped
image: phpmyadmin/phpmyadmin
environment:
- PMA_HOST=mysql
- PMA_PORT=3306
ports:
- “8081:80”
networks:
- net

php-fpm:
build: ./php
restart: unless-stopped
image: bitnami/php-fpm
volumes:
- ./app:/app
environment:
- XDEBUG_CONFIG=“remote_host=192.168.122.1”
networks:
- net

jasperreports:
image: ‘bitnami/jasperreports:7’
restart: unless-stopped
environment:
- MARIADB_HOST=mysql
- MARIADB_PORT_NUMBER=3306
- JASPERREPORTS_USERNAME=admin
- JASPERREPORTS_PASSWORD=bitnami
- JASPERREPORTS_DATABASE_USER=admin
- JASPERREPORTS_DATABASE_PASSWORD=xxx
- JASPERREPORTS_DATABASE_NAME=jasper
- ALLOW_EMPTY_PASSWORD=yes
ports:
- ‘8080:8080’
volumes:
- jasperreports_data:/bitnami
depends_on:
- mysql
networks:
- net

volumes:
data:
driver: local
jasperreports_data:
driver: local
networks:
net:

Thanks Sebt3. So my php code running in the container can’t see anything in the host volume? This will be an issue since the library I am trying to get working sticks the images uploaded into a dir there, and only keeps the address in the mysql. Is there a way to make the whole volume accessible from the PHP running in the container? I see the line
volumes:

  • ./app:/app
    Is this a bind mount? I thought a bind mount can only be setup in a Dockerfile, and I don’t know where that Dockerfile is located on my system. Would looking at the Docker logs help me in debugging this?

Here is some additional information.
When I run docker inspect I get:
richb201@richb201-XPS-13-9370:~$ docker inspect --format ‘{{json .Mounts}}’ 6ad | jq .
[
{
“Type”: “bind”,
“Source”: “/opt/docker-substantiator/app”,
“Destination”: “/app”,
“Mode”: “rw”,
“RW”: true,
“Propagation”: “rprivate”
}
]

This has been leading me to think that the problem is that the Propagation is rprivate (the default) rather than rshared. Is this the issue?

When I run:
richb201@richb201-XPS-13-9370:~$ docker exec 6adf ls -ls /app/assets/image_crud/views/list.php
8 -rwxrwxrwx 1 1001 134 5744 Feb 23 06:48 /app/assets/image_crud/views/list.php

I can see that the list.php file does exist! What is meant by the comment:

“The only thing I can tell you for now is : containers do not share the host “/” directory so depending on how you set things the file might not be available or at an other place.”?

I am not able to change the Propagation to “shared” to test my theory. You can see the way I created the volume
volumes:

  • ./app:/app

Is there any example of how to set the vol-options ? Also what is the significance of using “volumes” rather than “volume”?