-: In the last section,
we put together our Travis.yaml file
and built out some production versions
of each of our sub-projects.
So now that we've built out these production versions,
we now need to add in an additional step down here
to take those images and push them to Docker Hub.
Now, in order to push an image to Docker Hub,
we need to first log into the Docker CLI.
You and I actually logged into the Docker CLI in this course
way, way long ago when we first installed Docker.
You might recall that after installing Docker,
we ran Docker login,
and then we entered in our Docker ID and our password.
That associated our Docker client right here
with our Docker Hub account.
And so if you and I pushed any images up to Docker Hub,
they would be automatically associated
with your account or my account.
So we need to make sure that we do the exact same thing
inside of our Travis.yaml script.
Before we can attempt to push those off to Docker Hub,
we need to first log into the Docker CLI.
And so essentially,
we need to run the Docker login command right here,
and then enter in our username and our password.
Now of course,
we're not gonna put our password or the username
as plain text inside of our Travis.yaml file
because then other people
could very easily see that information.
So instead, very similar to what we did
on our last Travis CI project,
we're gonna set up some encrypted environment variables
that are only accessible by Travis CI.
And we'll add in our username and password over there.
So to get started,
I'm gonna flip back over to my Travis project.
Make sure that you're looking at the new repository,
or the new project that we just put together.
So you should see Multi Docker right here as the repo name
or whatever it is that you called it.
Then to enter in our Docker ID and our password,
we'll go to more options on the right-hand side
and find settings.
We'll then scroll down a little bit,
and find the environment variables section.
So for the environment variables,
we're going to enter in our Docker ID
and our Docker password.
So I will set the first one up with the name of Docker_ID,
and then I will enter in my Docker ID,
which is Stephen Grider.
Of course, you'll want to customize it
for your Docker ID in particular.
And I'll add that as a variable.
I'll then set up a second of Docker_password,
and then here I'm gonna enter in my password.
Now, not that I don't trust you or anything,
but I'm not gonna show you my Docker password.
I'm gonna enter it in on a second screen very quickly,
and add it as an additional variable.
There we go.
So I've now got my two environment variables
for the Docker ID and the Docker password.
So now we'll go back over to our Travis.yaml file,
and we're gonna add in a script line right here
that's going to log us into the Docker CLI.
And then once we're logged in,
we'll then be able to push all of our images off
to Docker Hub.
Now to log into the Docker CLI,
we're going to execute a command here
that's just a little bit more intense or complicated
than the Docker login we executed over here.
Remember inside of our terminal, we had ran Docker login,
and then we got two little prompts that said,
Hey, enter your ID and enter your password.
Now, unfortunately on Travis,
Travis doesn't really have support for a prompt like that
or a wizard like that assorts.
So we're gonna enter in
a little bit more complicated version
of the Docker login command.
Let's just write out the code or the configuration,
excuse me, the command that we'll need to log in,
and we'll talk about what it's doing.
So I'm gonna say Echo,
double quotes, dollar sign, Docker password.
Then after that I'll put in a pipe.
So that is shift, and then the character to the right
above the enter or return key on your keyboard.
And then we'll say Docker login, dash U,
and I'm going to collapse my sidebar
so you can see everything here.
We'll do another set of double quotes inside there.
We'll do dollar sign, Docker_id.
We're gonna make sure
that's the actual variable name I used, yep, it was.
We'll then close off the double quotes,
and then put in dash dash password,
dash standard in, or STDIN, like so.
All right, so what's this do?
Well essentially, again, we don't want to have to go through
the kind of little multi-step wizard
that Docker login usually presents you with.
Instead, we want to just do the entire login step
in one single command.
So the first part of this, Echo Docker password,
is going to retrieve your Docker password
from the environment variable,
and then essentially emit that over standard in
as input to the next command.
Or essentially the command
on the other side of the pipe right here.
So you can kind of imagine that your password is taken
and added in to the standard in channel
for this command right here.
We then run the Docker login command,
and add in your username as a dash U flag.
And then we tell Docker login that it can expect
to receive that password over standard in.
Essentially, this is how we log into Docker
in one single command.
Okay, so that's it.
Now that we've logged into the Docker CLI,
we can now take all of our built images
and push them off to Docker Hub.
So to push the images off, I'll put in dash Docker push,
and then all we do is list out the tag.
So we'll list out four separate Docker push commands,
one for each of these different tags that we have.
So I want to push the image with the tag of
Stephen Grider slash multi client.
I want to push Stephen Grider multi Nginx.
I bet you can guess the next one, multi server.
And of course, multi dash worker, like so.
All right, so that's all we gotta do.
As you might imagine, running Docker push
and pushing your image up right here
is just as easy as pushing your code up to GitHub.
Once you've done the kind of legwork
of building the image and logging into Docker login,
all you gotta say is Docker push,
and then the name of the image
that you want to push up to Docker Hub,
and Docker takes it from there.
So last thing we need to do is test out this entire script,
and make sure that we can successfully
push images off to Docker Hub.
So I'm going to flip back over to my command line.
We need to issue a new GitHub commit here
and push it up to GitHub,
or a new Git commit and issue it up to GitHub
to get Travis to run our project
and attempt to build these images for the very first time.
So inside the complex directory,
I'll do a Git status and verify that,
yep, we made a change to the Travis.yaml file.
I will add that change with Git add dot.
I'll commit it with Git Commit dash in, change Travis yaml,
and then I will push it up to Origin Master, like so.
So now in a moment or two,
we should see our Travis build come to life,
and attempt to build and then push our images
off to Docker Hub.
So I'm gonna pause the video right now.
I'm gonna wait about 5 or 10 minutes
for that entire process to be completed,
and then we'll come back together in the next section
and make sure that all of our images
were successfully saved to Docker Hub.
So quick break and I'll see you in just a minute.