I’ve made a lot of progress and have Docker running a few dev sites now, but have now hit my latest road block: Composer.
Admittedly, Composer is one of those things I have tried a few times in the past and have always failed to get my head around it or get it working. Yet everyone recommends you use it and every library you ever wanted to use recommends installing with it.
In the world of Docker I read that it’s incredibly “easy” to install and use Composer, as simple as adding one line to a dockerfile:-
I’ve done that, and it appears to install during the build.
But when I include:-
I get the error:-
Warning: require(vendor/autoload.php): Failed to open stream: No such file or directory
So the question is, where is the autoload.php file or the vendor folder, or where should it be?
I’m guessing there needs to be some additional set up, possibly in the docker-compose.yml file, maybe setting up volumes. But after a lot of searching, reading and trying things, I just don’t know.
I had already tried that one.
I’ve now tried all three paths, and none are working.
The thing I’m unsure of, and this is where Docker sometimes confuses me, is whether this file should be seen (exist) on my drive. Or does it exist only within the container? Because it isn’t present on my drive, if it were I would know where it is and have a good chance at giving it the correct path.
Did you try going to localhost? I didn’t try the IP address to see what happens. Did you follow the instructions exactly step by step? I used ubuntu-22.04. I will have to try the tutorial on other OS’s
If you are not doing this on ubuntu, where you see sudo in the instructions, those commands need to be run as root. All the other commands without sudo would be run as a regular user that you log into Linux with.
If you’re trying to use Docker Desktop you may have issues.
What is your exact setup you are attempting this on?
I did the tutorial I wrote twice to make sure it worked. There was no problem both times.
Composer is automatically installed and run when you run the container.
It will be a few hours before I can take a look at this.
I will give it in try in Windows. My setup was VMware workstation on Windows 10 with Ubuntu virtual machine.
It’s not a bad idea to set up your machine to run virtual machines. VMware has a free player and you can also get virtualbox which is also free. It would allow you to run multiple OS on your Windows machine
So ThisProjectFolder would be the one I open in the Linux Shell to run docker compose and contains the Docker config files.
In that is the app folder, it contains a .private folder where I keep my PHP includes above the public root. It has sub-folders, but no need to get too far into that.
And the public_html folder, the public root with my index.php.
The assets folder is just for public facing asstes like CSS, images, JS…
To have minimal code exposed above the public root.
For arguments sake we could say the require 'vendor/autoload.php'; is in entry.php though it is in an include within that. So within a file somewhere in the private folder.
But because we start off in index.php in the public root, I beleive paths will be relative to that.
That makes perfect sense to why it’s not found, if it is never created. So the problem shifts from locating the file, to properly installing Composer so the file exists.
Given the config files I posted earlier, I’m guessing I may need to set up a volume for Composer to put its files in. Is that correct? Or do the build errors point to something else wrong?
The different OS may well be the problem.
It may be my ignorance of all things about server config, but I thought that was (one of) the point of Docker: The host OS shouldn’t matter, because you are creating virtual Linux servers which should be set up the same wherever you run them.
I have played around with VirtualBox before, with an Ubuntu VM. I thought it would be odd running Docker in a VM, since it would be like having a VM within a VM. But I don’t know, as you may gather, server set up isn’t my strong point.
This is a project zip. It’s actaully just stripped down to the bare bones to avoid the complications of the full (unfinished WIP) thing with database and all the rest. It’s really just the initial Docker set up that is the concern. Docker.zip (5.4 KB)
An interesting point about that. On earlier attempts when I thought Composed had installed, the build did go through the process of getting phpmailer.
When I later comment out the (failed) Composer instalation lines to make it run, and forgot to also comment that line, it errors on that line (for obvious reasons).
But the confusing part is, that it didn’t error on it before, as if Composer was working.
The problem I am having now is getting the server to see the index.php. I get the defaault server page no problem but I get a 404 for the index.php. NGINX is not looking in the app/public_html despite the config setting.
The error log shows NGINX is looking elsewhere for it.
/usr/share/nginx/html/index.php" failed (2: No such file or directory)
This is the first time I have ever messed with NGINX. Taking a lunch break from this for a bit.
I have not looked at your zip yet. Shouldn’t make a difference though.
I had no problem getting a container to run. The problem arises when I tried to include the autoloader, which apparently doesn’t exist.
Though when I run the composer install line as @rpkamp suggests, I get an error on build.