Now for this course section, I got another small example,
which you again find attached.
It's a very simple note JS API application again,
with one note JS file.
This app JS file, where we in the end again
create a node server and listen 3000 in this case
and where we then have two end points.
We handle gets requests to our domain slash story.
And we handle post requests to our domain slash story.
And here in the post request handler,
we in the end extract some text
out of the incoming request.
We check whether it's empty or not,
and if it's not empty, we appended it to a file
in our file path,
which is this one here.
Which in the end means we're looking for a story folder
and in there a text dot text file.
And there we add the text sent by the user
through this request.
Well, and forward to get route for this get request,
which we're handling,
We are reading that file
and we are returning the data which we read.
This is a very simple application
and it will in the end to write data
to this text text file into the story folder,
which initially is empty of course.
And so that we can see this in action,
I prepared a Docker file
for building this node application image
and a Docker compose file for running that image
and for building it and starting to build process as well
because here I'm using volumes.
Because of course I got some data into story folder here
which showed survive container removal and restarts.
And of course we could also just run our image
with Docker run, and add a volume with the dash V flag
but so that we don't have to write this
a bit longer command,
I prepared this Docker compose yammer file.
So what we can do here
is we can now run Docker compose up dash D
maybe all the dash dash build
to always ensure that the image is reevaluated
and possibly rebuilt if something changed.
And once that is up and running,
you can use a tool like postman
to send requests to this dockerized
and now running application.
For example, I gets request to local host slash story,
to get any safe stories.
And initially of course, that returns a valid response
but an empty string here,
but you can also send a post request
to local host slash story,
and then go to body and add a raw JSON body here.
And then between curly braces and double quotes,
add text like my text and send this
and this will now be stored.
And if you now reload or a resend to get request
you see your text,
and then this line break which is automatically added
by the node JS code here
when you store and use story here.
So this works and of course
since we're using a volume,
if we run Docker compose down
and therefore the container gets removed in the end
it gets stopped and all the remove.
We can of course ensure that everything
what we have on containers is removed
by running Docker container prune
and then entering why to confirm this.
So if that is all removed,
if we rerun the up command Docker compose up,
of course we'll see that if we sent this get request again
this data is still there.
Because even though the container was stopped
and removed with the help of a volume,
it was stored and therefore persisted.
And that's not something new,
that is something you already did learn about earlier
on in the course,
we learned how to work with volumes.
And we learned that volumes are a powerful tool
when working with Docker because volumes allow us
to process data across container restarts
and especially removals.
So with that, I'm going to run Docker compose down again,
to stop this container again.
And I'm now going to dive into how this translates
to Kubernetes and how we work with Kubernetes and volumes.