YouTube Transcript:
The Only Docker Tutorial You Need To Get Started
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
View:
hi so you're a developer well you think
you're a developer nice building apps is
pretty cool except when it's not let's
say you're building a web app the web
app works perfectly hey it's not working
what yeah it's not working but it works
on my machine this has happened since
the beginning of Technology let me show
you hey it's not working it works on my
machine now this has happened or will
happen to every programmer we call this
developers law any code that works
perfectly on your machine will
inevitably fail on everyone else's I
made that up by the way but what if I
told you there's a way to prevent this
this is Docker Docker I hardly know
her so what's Docker well it's the
sponsor of today's video oh no wonder
Docker is the number one most used
developer tool based off a stack
Overflow survey that helps you develop
ship and run applications within
lightweight
containers what okay so Docker is
actually pretty simple and something you
should know sloth why should I know
Docker you should know Docker because a
lot of tech companies use it because it
makes development and deployment easier
yeah that makes sense plus it's a skill
that's in a lot of job posting which
means learning Docker will make you
money yeah that makes sense what makes
Docker so good Docker essentially allows
us to package up our code imagine Docker
like a Lunchable the Lunchable has your
trash code dependencies like no. JS or
python environment settings and
everything else needed to run your trash
code you can bring that Lunchable
anywhere and give it to anyone at school
at work you can let your friend have it
I like my cheese drippy bro no matter
where or who uses it it works so
basically Docker makes it easier to run
your code on any computer because it has
everything you need to run the code no
need to install anything Docker does it
all for you yeah that makes sense now
how does Docker do that Docker doeses
this with two important Concepts that
you have to know images and containers
everything revolves around these two
concepts so don't forget them you can
think of images as the recipe it
contains all the ingredients and
instructions this means a Docker image
contains the technology we need run time
and any system tools we need to run the
specific code now we need something to
actually run the code which is where
containers come in a container is like
the actual meal it's what gets made from
the recipe now the cool part about
containers with one image we can create
multiple container
instances what now what does this mean
it means as long as you have the docker
image you can create a container and run
the code you want proof here's me
running a Docker image that contains
Doom yeah the entire game of Doom to be
fair you can run doom on almost anything
but this is what makes Docker amazing it
allows us to simplify the process of
sharing code you no longer have to do a
tedious process like installing all
these tools and making these
configurations to run some code all you
need to do is run one Docker command and
it does the rest for you yeah that makes
s i simplified this explanation a lot
because a lot of you have a shorter
attention span than a goldfish so if
you're a nerd and you actually want to
learn more about Docker I'm going to
have links in the description if you
want to do your own research or you can
check out my free newsletter called
sloth bites where I give you free
programming information every week to
make you a better programmer and did I
mention it's now that you understand why
Docker is important and how it works
kind of let me show you how to actually
use it step one download Docker
obviously go to doer. or click the link
in the description and download Docker
desktop it'll download Docker for you
and it comes with a nice little gooey to
manage your images and containers but if
you're feeling like a grownup it also
comes with the docker CLI so you can do
everything in the terminal step two
check if you have Docker open up your
terminal and type Docker D- version if
you see this you have Docker installed
if you don't then uh good luck little
bro figure it out step three set up
Docker on your IDE of choice I'm doing
vs code because I hate myself make sure
to download the docker extension on your
IDE because it'll have language support
and other goodies that will make your
life so much easier step four the docker
file this is pretty important now what's
a Docker file remember our recipe
analogy this is literally where we write
our recipe let's write one together here
we have a simple node server yeah you
heard me node JavaScript first we're
going to create the docker file and
inside this file we're going to write
the steps and instructions to run the
server now in order to write the steps
you need to know the steps so you need
to understand how to run the server but
since we're using JavaScript it's pretty
easy first you get your code then you go
into the file or directory download your
dependencies and then you run the server
with the mpm start command bada bing
bada boom easy peasy now that you
understand how to run the server all we
have to do is write all that in our
Docker
file what so at the top of your Docker
file you're going to write from and if
you downloaded that Docker extension I
told you to get like the good boy you
are if you hover over it you're going to
get some nice documentation every Docker
file starts with this command now we
have to select a base image and a base
image is basically just our starting
point we can use the officially
supported node.js base image that comes
with everything we need so in our Docker
file we're going to write from node
colon 22 all we have to do now is write
the instructions to start the server so
underneath the fir command you're going
to type worker slapp worker stands for
working directory and this is basically
us telling Docker hey start at this
point this is where our code's going to
be the next step is a very important
step so you better listen to this step
usually in a node project we get our
code and then download our dependency we
could do that in Docker but that's not
the best way instead what we'll actually
do is we're going to download our
dependencies first and then get our code
so we're going to write these commands
this First Command copies our package
files and the second command well it
should be pretty obvious it installs our
dependencies now why are we doing this
unlike you and me Docker is actually
pretty smart it has this thing called
layer caching you can basically imagine
every step that we write as a layer and
Docker looks at every layer individually
so for layer caching it goes like this
layer changed do it again layer did not
change use cash that's it so the reason
we do this for our dependencies is every
time we change our code it's not going
to download the dependencies again it's
just going to use the cash so it
basically skips this step which makes
our builds way faster our next step now
is to copy the code into the image we do
that with this command wow now this
command copies everything all our files
and our folders into the docker image
but this is a problem since we're
copying everything that also means we're
copying our node modules that's not good
because this file is big but not as big
as your M we need a way to ignore that
file we can do that with a Docker ignore
file and inside that file we're going to
add the node modules folder and any
other files you don't want in there on
to the next step in our code we have
this port environment variable we need
to add this into our darker file we can
do that with the EnV command now since
this environment variable is a port
we're also going going to need this
command this basically tells Docker hey
we're going to need this port now it's
time for the last step running the
server we do that with this command whoa
whoa whoa whoa why'd you do it like that
and why didn't you just use Run mpm
start like you did for install good
question actually the reason is because
the Run keyword happens when we're
building the image while the CMD keyword
is what Docker uses to actually start
the container if we use the Run keyword
for this step the container would never
start anyways enough Yap our Docker file
is complete step five building the image
we're going to have to be grown-ups here
and use our terminal to build your image
we use Docker build command so inside
your terminal you're going to type
Docker build- t t stands for tag and it
basically means give your image a name
tag understand so give your Docker image
a name you can name it whatever you want
the last thing we're going to add is the
path to our Docker file which in our
case is the current working directory so
all we have to do is type A period run
this command and you're going to see
Docker running all the steps we wrote in
our Docker file step six running the
container we can do that with the docker
run command make sure you write the name
you gave your image hey what's that Das
P this- P is for port forwarding you can
do your own research search for that but
for now think of it as a bridge between
our computer and our container the
number on the left is the port for our
computer and the number on the right is
the port for the container you don't add
this part it's not going to work go
ahead try it I dare you run the command
and you're going to see that your node
server is now running congratulations
buddy you know the basics of Docker I'm
proud of you step seven debugging even
though Docker makes it easier for us to
share code it doesn't stop us from
building our containers wrong or from
writing trash code luckily debugging and
checking any logs is pretty easy with
Docker desktop so open up Docker desktop
top and look at the container that's
running it should have a little green
dot click the container and you can view
any logs you can execute any terminal
commands and you can see how the
container's doing pretty simple now if
you think you're too good for a gooey
you can also do this in the terminal
with the docker exact command step eight
Docker Scout now if you notice when you
ran the docker run command Docker gave
you a recommendation to run this command
Docker Scout quick view now what's
Docker Scout it's a tool created by
Docker that looks inside your Docker
image and it generates a detailed report
of all the packages that's inside your
image and it's looking for any
vulnerabilities inside those packages if
it detects any vulnerabilities it'll
give you suggestions on how to handle
them using Docker Scout is pretty simple
you can do it with the terminal or with
Docker desktop I personally recommend
Docker desktop it's really easy let me
show you how to use it all you have to
do is go to your images click on the
image that's running and once you're
there you're going to see this
vulnerabilities tab with a button that
says start analysis click the button and
you're done it's that simple step number
nine Docker compose and Docker volumes
let's be honest here this note example
was really simple nowadays babies in the
womb can do this example what if we
wanted to add a database what if we
wanted to add a front end how do we add
that with Docker now you could combine
all of them into one giant container but
I don't recommend that a lot of people
don't recommend that please don't do
that it's pretty stupid now the way
people usually do this is they separate
each of these services and put them in
their own containers and this is called
a multicontainer application what an
obvious name right but this creates a
brand new problem now that you have
multiple containers you have to run
those containers separately and you have
to find a way to connect them all
together and manage them this this is a
lot of work and a lot of areas could go
wrong trying to manage these containers
lucky for us a lot of programmers are
lazy just like me which is why we have
this tool called Docker compos Docker
compose is pretty easy to understand it
basically tells all your containers how
to work together to create the full
application let me show you a quick
example on how to use it let's pretend
we added a database to our node server
so the first thing we're going to do is
create a composed. yo file and inside
that file we're going to create an
object called services and inside that
service object we're going to be writing
down keys that represent the containers
we want to run so in our case our back
end and our database since our backend
is using a Docker file we created we're
going to use the build key and the value
is going to be the location of our
Docker file which in our case is the
current working directory so it's going
to be a period and remember our backend
needs port forwarding so we're going to
add that in our configuration to and now
moving on to our brand new database
container what we're going to put inside
of this one is the image key because
we're not using a Docker file for this
database instead what we're going to do
is use a base image of the database we
want to use which for this example I'll
go with postgress now now our database
also has some environment variables we
have to add so we can do that with the
environment key and underneath that we
just add all the information okay we're
almost done I swear I pinky promise we
just need to add one more thing and
that's a volume whenever we close our
containers we lose all the state and
data and our containers right now don't
share data between each other so we need
to add a volume what is that all right a
volume is basically just a folder on our
computer that Docker can access to save
any data from our containers and to
share that data with other containers
and it's pretty easy to create inside
your Docker compos file you're going to
copy down this stuff and this line right
here says Hey Docker create a volume
called postgress data and the other one
tells Docker hey we have this volume
here this is how you connect to it our
Docker compose file is now complete all
we have to do now is run this command in
our terminal Docker compose up and
Docker will find this configuration file
and run all the containers together and
if you want to shut down your containers
then run this command Docker compose
down and that's all you need to know
about Docker compose because I'm too
lazy to teach you anything step 10
Docker build Cloud if you noticed
building our containers takes a bit of
time even for the simple notes server
now imagine how long these containers
take for a complex application
apparently based on this 2022 survey
from incredib build the average
developer loses an hour just waiting on
their Docker build Docker realized this
problem and recently created something
to help reduce build times they created
Docker build cloud and the main
difference is it builds your containers
using the cloud yeah it's it's in the
name now when docker's words using the
cloud allows your builds to be up to 39
times faster plus if you're working with
a team you can share the same cash with
them so one person can build the image
and now everybody can use that same cash
which speeds everything up for everybody
so if you have a more complex project or
have a Docker project that takes forever
to build you should probably check out
Docker build Cloud I'm not going to show
you how to do it because I don't have a
complex project uh
step way okay so I'm not going to lie to
you all I kind of wasted your time you
could have just done Docker and N in
your terminal and Docker would have
created everything for you so uh thanks
for letting me waste your time bye
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.
Works with YouTube, Coursera, Udemy and more educational platforms
Get Instant Transcripts: Just Edit the Domain in Your Address Bar!
YouTube
←
→
↻
https://www.youtube.com/watch?v=UF8uR6Z6KLc
YoutubeToText
←
→
↻
https://youtubetotext.net/watch?v=UF8uR6Z6KLc