So let's get started writing some code here.
I'm in a empty folder,
and I just wanna really emphasize
that I don't have Composer and so on installed.
If I try to run this, I get command not found.
So here, I'm really missing some of the tools
which we need to build a Laravel application.
And therefore, we're going to use Docker for that.
And I am going to start by adding a docker-compose.yaml file
because we are going to build multiple containers,
and these containers need to interact,
and I also, even if it would be just one container,
I also like to have this configuration in a text file
which is easy to read and change.
So we'll use Docker Compose
to set up this entire application, this entire project,
and it will hold both the application containers
as well as the utility containers.
And I will also show you how you can run all
or just some of these containers throughout this module.
So let's get started by adding a version.
And, again, I'll lock in version 3.8 here.
And then, as a next step, let's specify our services.
So our containers, which we want here.
Now, I showed you on the slide
that we'll have six different services.
We'll have our server service, the nginx server,
which will in the end take all the incoming requests
and trigger the PHP interpreter.
We'll have the PHP container therefore,
which is responsible for running and executing our PHP code
and therefore also the Laravel code
because Laravel is just a PHP framework.
We'll have the MySQL container,
which holds the MySQL database,
and then we'll also have these utility containers.
We'll have the composer container,
we'll have the npm container,
and, maybe in front of that, but the order does not matter,
still here, I'll have my artisan container.
So these are the six containers we need here.
And I will, of course, add them step by step.
And let's start with the server.
Now, the server, as I mentioned, will use nginx,
which is a very popular, and powerful,
and efficient web server.
Now, the great thing is that if you Google for docker nginx,
you find an official nginx image which you can use.
So just as with MongoDB or Node,
we also have an official image for that.
And we can simply use that to set up a nginx server.
You will also find documentation
on how you may use this image
here on this Docker Hub page, of course.
But we, of course, will set it up together anyways.
So back in the docker-compose file,
we can now specify an image for the server,
and we'll use an official image here, the nginx image.
And now, there again, we've got multiple tags,
multiple versions of that image we could use,
and I will use this stable-alpine tag here
to give us an image, which again is based
on this very slim Linux operating system layer,
and then obviously a stable version of this nginx image.
So here, it's :stable-alpine, which I wanna use here.
And even though you don't have to,
I'll put that between quotes.
It's often a bit safer to do that for text
to ensure that nothing is somehow interpreted
in a wrong way.
Great, so that's the image we wanna use for our web server.
Now, this web server also exposes a port.
And how do I know that?
Well, the official documentation tells us.
It tells us here for example that we can expose this port 80
which is, as it seems, exposed internally by that image.
So therefore I wanna bind this port
with the ports option here to some port on my host machine.
And there, I'll use port 8000
and bind this to the port 80 exposed by this image,
and therefore by the running container.
Now, we'll be able to spin up a container
which has a server in it.
But this server out of the box isn't too useful.
It won't really know what it should do.
And what it should do in this application
is that it should have a look at incoming requests
and eventually funnel them to our PHP container,
which we'll have later,
and let that container execute our PHP code.
So to provide our own configuration,
I'll add a bind mount here with the volumes key.
And here, I wanna bind a local folder,
let's say a nginx folder which we have yet to add,
and in there, a nginx.conf file,
and you can also target individual files
in case you don't wanna bind a complete folder,
but you just wanna copy one specific file into a container,
then you can target that specific file.
And, in the container, I wanna bind it to an absolute path,
which should be in the etc folder,
then nginx, and then nginx.conf.
And in case you wonder why I picked this path specifically,
well, because the official docs
for this image tell me to do that,
and that is how you work with these official images.
You don't just know which ports are exposed
or which folders do something special in the image,
instead you have to read the documentation
to learn such things.
And here, we learned that we can pass in
our own configuration by binding
to this container internal path.
And we can, of course, also set this to read only
because the container should never change
that configuration.
And this will allow us to pass our own configuration file
for this web server into this web server container.
Now, we still need to create that on our host machine,
so I will add an nginx folder here,
and in that folder, an nginx.conf file.
Now, you find the actual configuration file attached
to this lecture because I already prepared it for you.
So you can just use this finished file here.
And this file in the end has some nginx configuration inside
which basically listens on port 80,
so we could change this here now
if we wanted to listen on a different port
inside of the container,
which then handles requests to index files,
which then also makes sure that we look
in this directory for files
that we can use to respond to the incoming request.
This directory will become important soon.
At the moment, we don't have it,
neither in the container nor here,
but I will come back to that.
And then, we have redirection rules,
basically ensuring that all incoming requests
are redirected to index PHP files,
or requests that do already target PHP files
are in the end then forwarded to our PHP interpreter.
And that's, of course, not something
which will work right now, but it will work later.
So let's save this config file
and let's go back to the docker-compose YAML file.
Because with that, we also ensured
that we added our configuration here as a volume.
And that is it for this server container.
I am fully aware that this was brand new
and maybe not something
you would feel comfortable building from scratch,
but that is why we're going through that together
so that you see many examples and that you understand
why we, for example built this container like this.
With that though, we got this nginx container built,
and now we can move on to the PHP container
in the next lecture.