Dockerfile not found with docker-compose

Hello,

I’m trying to build a PHP/MYSQL stack using docker-compose (in Portainer). Everything works, until I try to add the mysqli extension to PHP.

I specified the path to the Dockerfile in my docker-compose :

version : ‘3’
services:
nginx:
image: nginx:1.22-alpine
ports:
- “4580:80”
volumes:
- /home/docker/appdata/wwwseb/config/code:/code
- /home/docker/appdata/wwwseb/config/nginx.conf:/etc/nginx/nginx.conf
php:
# image: php:8.3-fpm-alpine
build:
context: /home/docker/appdata/wwwseb/config
dockerfile: Dockerfile
volumes:
- /home/docker/appdata/wwwseb/config/code:/code
mysql:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: xxxxxx***
MYSQL_DATABASE: xxxxxx
MYSQL_USER:** xxxxxx**
MYSQL_PASSWORD:*** xxxxx
volumes:
- dbdata:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: xxxxxx
ports:
- “4581:80”
volumes:
dbdata:

and I get the following error: “Failed to deploy a stack: services.php must be a mapping”.

The file is indeed present under /home/docker/appdata/wwwseb/config

Contents of the Dockerfile:

FROM php:8.3-fpm-alpine
RUN docker-php-ext-install mysqli

Any idea where the error is coming from?

Hello

This type of error isn’t about the dockerfile but the yaml one. Make sure your compose.yaml file is correct. Check also your indentation.

Hello,

Thanks for you reply. I found error in the yaml (bad indent)

However, how use a Dockerfile in a specific folder ? I tried many configurations but not successfull.

i.e:
build:
context: .
dockerfile: /home/docker/appdata/wwwseb/config/Dockerfile

Error : failed to deploy a stack: could not find /home/docker/appdata/wwwseb/config: stat /home/docker/appdata/wwwseb/config: no such file or directory

In this case, what is the location of the context ? how can i know th path ?

On my own I’ve never used a fullpath, always a relative one.

I always put my dockerfile in the same folder than the yaml or in a subfolder, never else where.

Not sure it can work and not sure it’s a good idea (all projects should be standalone, all files have to be stored in an application folder you can then push to github.com f.i.)

I don’t think you can use a full path for Dockerfile, but it must be relative and inside your context (for security reasons).

If it says the folder is not there, it is either not there or Docker has no access to it. Make sure you install Docker from an official repository, not the snap version (It has access to your home only). Use docker compose instead of docker-compose just to avoid using an outdated version. And also make sure you have no typo in the path.

You could not refer to files outside the context from a Dockerfile, but the Dockerfile itself can be anywhere. I wouldn’t put it anywhere either, but it can be.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.