In docker compose,
let's continue with the artisan container.
We need the artisan tool to run certain level commands.
For example, to populate the database
with some initial data.
Now, the artisan command, again, needs a custom docker file.
However, I will simply use the PHP docker file here
because I just need the same setup as we have it in here.
So we can add the build configuration here
or simply copy the one from the PHP container
and add it here for artisan.
Because it needs PHP to execute code.
Artisan is a level command built with PHP.
So it needs PHP to do that.
Now, in addition, it needs volumes
and there specifically it again, needs our source code.
Because it is executed on our source code.
We do things with our source code with that command.
So we expose the source directory on our local host machine
queue to good old /var/www/html folder
inside of this container,
because that's where our application will reside.
And now I'll show you something interesting
which I haven't shown you before.
You can actually also set certain settings
which you set in a docker file normally,
inside of a docker-compose file
to essentially override the settings
inside of the docker file.
And here I'm using the PHP docker file because I want PHP.
I'm also happy with this working directory
but I also want to add an entry point.
And in the PHP image, we don't have an entry point.
Simply because this PHP container, is in the end used
by nginx to funnel individual files through it.
So it's used like a utility container
for nginx you could say.
This is all good, but now I need to run my own command.
And I wanna specify this as an entry point.
We could create a separate docker file,
but we can also simply add the entry point option here
in docker compose.
And this allows us to override
or add if it doesn't exist yet
the entry point in a docker file.
So here we then specify it just
as we would to do it inside of the docker file.
And here I want to execute PHP.
So this tool the executable,
which is set up by this PHP base image.
And I wanna execute a certain file with PHP.
And that file can be found
in the /var/www/html artisan folder.
Or to be precise in the HTML folder
and then it's the artisan file.
And we can see this file in the source folder.
It's this file here.
This is a PHP file, but when you execute it
it runs a utility program, which can do a lot of stuff.
It's part of the level framework.
And we're executing this file inside of the container
with help of PHP and this PHP image.
And we're adding this entry point to the image
since it doesn't exist in our docker file.
And we also don't want to add it here
because we use this PHP docker file
all to folder PHP container.
And here, we don't want the entry point.
So this is the setup we need for artisan here.
Now with that, we already finished this container
and let's also finish NPM now.
NPM is quite simple, here I'll use the node image
and there let's say node 14.
And now we could either write a docker file
to set the working directory and the entry point
or we use our newly gained knowledge that we can add
or override certain things here in docker compose.
And we can utilize this to set
the working directory here as well in docker compose.
And that's what I mentioned earlier.
You can do this here as well.
I prefer docker files, but to show both I'll now do it here.
And I'll set the working directory to /var/www/html
as so often and enter entry point,
which in this case is NPM.
So that we expose this NPM command
from inside our image, based on this node image
so that we can use this NPM container
to run NPM commands, inside of it.
And now, I just also want to add a volume here.
Because, I again, want to of course do all of that
on my source code folder, and therefore bind that
to the /var/www/html folder inside of the container.
Same logic as for artisan.
And now with that, we're done.
Now, make sure that you got
your application servers up and running.
And let's now try the artisan command.
And for this, we can use docker-compose run
and then run the artisan container.
Which internally then runs this artisan file
with PHP
at --rm though.
So that it's removed and we're done.
And now run the migrate command.
Which is one of the artisan command's level supports.
This will write some data to the database
and it will therefore also check
whether this database set up works.
So let's hit enter, and this looks good.
It's migrating and it migrated successfully.
And this wouldn't work
if we wouldn't have a database connection.
So, with that, we also tested this.
We're not going to test NPM here, but it should work.
And we now have a nice setup here
for a level PHP application.
Yes, this definitely is a more complex setup
but that's also the idea behind the course.
Learn the basics and then also see more complex things
being built with that.
Now, when you build something like this on your own,
it's totally normal
that you build something like that step by step
by googling, finding other solutions,
taking courses like this
and eventually you'll get to the point
where you can build something like this totally on your own.
Obviously, it also helps if you know level and PHP
because you then know the building blocks you'll need
like composer.
If you don't know that, you obviously also have no chance
of knowing that you need to add it.
So don't be discouraged by that
if you don't know PHP or level.