Now to create this utility container, I need my own image.
And therefore I'll add a Docker file.
Now I wanna start based on node again.
And I will actually pick a specific node version here,
I'll use the 14 dash Alpine version,
that's still node version 14,
but it's using an extra slim operating system layer
under the hood.
So it will simply be a smaller node image.
Of course, we could also just use node.
But since I want to build a utility container,
I want an extra slim setup here.
So I'll use this Alpine version,
which is this very slim and optimized node base image.
Now with that, we can add a working directory
and set this to app, for example, to define
which folder will be used by commands
executed on this container and on this image,
and that includes commands you entered with Docker run,
anything which you enter after the image name
will also run against this default working directory.
And then we could specify a starting command here,
for example, NPM init.
But I want to make my project here more flexible than that,
I don't want to restrict this image to just being able
to run the init command,
I want to give the user full control over this image
and allow the user to run any command against this image.
So I'll just save it like this.
And then I'll build this and give it a tag of node util
for node utility.
And this will now download this node Alpine image,
which is super small as you can tell only 35 megabytes here,
and it will then build this.
And thereafter, we can Docker run our node util, image,
and then for example, pass in NPM init.
Now, again, we need to do this in interactive mode,
to stay connected and to be able to enter values.
But I also wanna do more than that, by default,
this command would run in the app folder
inside of the container.
Now I want to mirror it to my local folder
so that what I create in the container
is also available here on my host machine.
So that I can create a project on my host machine
with help of a container.
That's the idea behind having a utility container,
we can use it to execute something
which has an effect on the host machine
without having to install all the extra tools
on the host machine.
And we can use a feature for that,
which we already used many times before in the course,
we can use a bind mount with dash v here.
And I can bind my folder here
to the working directory I have in there.
So I'll just copy this path here.
And specify unspecified that without the file name,
and then a colon and then the path inside
of the container/app,
which is the working directory
in which NPM init will run.
And now if we hit enter, we start this container.
Now we have to fill out these questions
we have to provide answers,
we can use some default values here if you want to.
And once we're done, you see the package JSON file appear
here on my host machine.
So in this project folder on my host machine,
because of this bind mount,
we're sharing our host machine folder here
with the folder inside of the container.
And commands which we execute inside of the container
inside of this shared folder they offer also have an effect
on our host machine.
And now I could totally uninstalled node
and NPM on my host machine.
And I could still create projects with help of NPM init
with help of this utility container.
And that might sound like a constructed or dumb scenario.
But actually it can be really useful
that you don't have to install all these extra tools
on your machine.
For node It's not too bad.
It's just one tool node JS But for Laravel and PHP,
as I mentioned, it will be way more complex.
And I'll come back to that example
and show you a Laravel PHP setup with help of Docker
once we're done with this section,
because that will always be quite interesting.
But as I just said once we're done with this section,
because there actually are a couple of other neat features
which can make working with such utility containers
more convenient.