So now that Docker is installed
and up and running on that remote machine,
we need to bring our local image onto that remote machine.
And for this, we got two main approaches.
Option number one, is that we deploy our source code.
So, we find a way of copying our source code,
so everything in this project folder,
including the Dockerfile file onto that remote machine
and then we build it there, we build the image there.
The alternative is that we build the image ahead of time,
for example, on our local machine.
And we then just deploy that built image
onto the remote machine.
So, it's simply about building the image
on the remote machine
and doing that by pushing our source code there
and running Docker build there and then Docker run,
or if we want to build it locally, for example.
And then just execute Docker run on the remote machine
once we got the image there.
And the first option
has a lot of unnecessary complexity to it, to be honest.
We need to do a lot of unnecessary work
on the remote machine.
Why would we build the image there?
Which advantage does this give us?
I'm not sure if it gives us any advantage.
I'd rather prepare everything locally
and have the finished image, locally,
and then just get my finished image onto that remote host
to then run it there as a container,
and we can use Docker Hub for that.
We can build our image locally, then push it to Docker Hub
and then pull it from the remote server
to then run it on the remote server.
And that's exactly what we're going to do.
So, for this, make sure that you do log into Docker Hub.
We did set up an account early in the course already,
and I did talk about Docker Hub there already.
And then there, click create repository
and create a new repository.
And I'm going to name it, node-example-1
but the name is up to you.
So, I'm creating this new repository on Docker hub
and I'll set it to be a public repository here
since you only have a limited amount
of private repositories if you're not paying.
And simply click create, then...
And now, we can push today's repository
by creating an image, locally, on our machine,
which has this repository name as a name.
So, for that, I'm going to open up a new terminal,
which is now not connected to my remote server.
This first terminal still is connected via SSH.
This terminal here isn't.
And you can tell by the way this input starts.
If it says ec2-user@ something,
or if it doesn't say that.
And then on my local terminal,
I'm going to build this image here.
And actually, before I do that,
I'm going to add a .dockerignore file,
and I'm going to ignore node modules
if we would have it here,
ignore the Dockerfile and ignore any .pem files
to not put this key into my image.
I don't want to share it with anyone, so I will ignore it
so that this key file is not getting added to my image.
And with that created, we can now run Docker build dot.
Give this a tag of node-dep-example-1, for example,
and hit enter.
And now this image is built
and we now have this image locally.
Now, as I explained earlier in the course already,
we can now push this image to Docker Hub by renaming it.
And we can do this with the Docker tag command.
And here, I want to give a new tag to this image here,
the node-dep-example-1 image.
So, we can run Docker tag and then use this image name
and then use, in my case, academind/node-example-1
as a new name with or without a tag.
The tag is optional, so I will just focus on the name here.
And of course, you should use your repository name here.
So, for me, it's this one
and enter this here.
And now if we list all images again,
we see we have our old image,
but also the same image with a different name now.
And this allows us to then run Docker push
with that tag or with that name,
and this image will be pushed.
However, this will fail if you're not logged in.
So, let's log in first
with your Docker Hub username and password.
And once you did log in successfully,
you can run this Docker push command.
And now, this locally built image is pushed to Docker hub.
And that means that now,
the image building process is already finished
and on our remote machine,
we now just need to run it.