‫Hello, this video is for two reasons.
‫One, it is in case you don't ‫want to run Docker locally.
‫You want to run Docker on a server ‫remotely, whether it's for production,
‫some other server use, or simply ‫because you can't run Docker locally
‫for licensing, performance, resources, ‫you you're not local admin, it
‫could be all sorts of reasons.
‫So this is about Docker ‫engine for Linux servers.
‫The reason I say it's engine and ‫servers are key components we'll
‫get into throughout this video.
‫This video is going to focus on getting ‫the most up to date Docker installed from
‫the correct location, which is different ‫than your default Linux package managers.
‫We will then make sure that ‫the CLI is installed wherever
‫you're going to operate it from.
‫So not SSH-ing into the ‫server the entire time.
‫We're actually going to set it ‫up so we can control it remotely,
‫which is the best way to run a ‫Docker engine on a Linux server.
‫And a little disclaimer, if you ‫haven't watched the previous video,
‫which is about Docker Desktop for ‫Linux desktops, this is not that.
‫This is before we had Docker Desktop, ‫we had just the Docker Engine.
‫Every Docker Desktop ‫has Docker Engine in it.
‫It manages it for you.
‫But Docker Engine, it's a single binary ‫called dockerd or the Docker daemon, and
‫that can operate on any Linux server.
‫As long as you have a Linux ‫kernel, you can run that.
‫The same thing, you can run it on a ‫Windows Server, the dockerd.exe that
‫could actually run as a service on a ‫Windows Server to run Windows containers.
‫But we're not going to talk ‫about that in this video.
‫So the Docker Desktop, that's ‫for running on your local system.
‫That's really just for ‫local use of Docker.
‫But this is the Docker Engine, which ‫can run on any Linux system, whether
‫it's local or remote, whether it's ‫a VM or a physical server, it's
‫a Raspberry PI, whatever it is.
‫If it's running a Linux ‫kernel, it's in the list.
‫And Docker has a compatible ‫list of tested, supported
‫builds that they know work.
‫It's not every Linux ‫distribution out there.
‫It doesn't include BSD, which ‫is not technically Linux.
‫And it's really just ‫focused on the big ones.
‫You know, the CentOS, the RedHat, the ‫Ubuntu, the Debians, those kind of things.
‫And there's various architectures ‫that it will support.
‫So as a reference in this video, you'll ‫see the link to this page, which is
‫showing you the list of currently ‫supported Linux distributions for Engine.
‫I am of course, going to use ‫Docker on Ubuntu, my favorite
‫server Linux distribution.
‫And I'm going to step you through it.
‫I'm going to gloss over the details ‫because really, you're just going
‫to read this or run the script, ‫which we'll talk about next.
‫Now, yes, I am giving you links ‫as the resources to this video for
‫all the documentation around all ‫the ways to install it on Linux
‫variants, distributions, like Ubuntu, ‫Fedora and all the other ones.
‫But really, the easiest way to do this ‫most of the time is just running a script.
‫If you type in your browser ‫get.docker.com, that will give
‫you a shell script that you can ‫look at, you can download, you
‫can run automatically with Curl.
‫It's meant to basically get you the ‫right settings and uninstall the old
‫things, install the new things, make ‫sure you're getting the right sources
‫and all that stuff all in one go, which ‫is how I've always installed Docker
‫ever since I learned about it, way, way ‫back at the beginning of the project.
‫So maybe for learning, maybe the ‫first time you install Docker on
‫a Linux server, you go follow the ‫documentation that goes through step
‫by step with your package manager.
‫Maybe it's apt, maybe it's yum, maybe ‫it's apk, just depending on what
‫you're doing on your Linux distro.
‫But I'm going to use this ‫script, which is easier.
‫It's basically Curl-ing down ‫the script into a file and then
‫running that file with a shell.
‫And this is exactly what that script, ‫if you went to the last slide, it
‫would tell you to copy and paste that ‫and copy it down and then run it.
‫So we're doing that, and it will figure ‫out which distribution I'm on, which
‫version of that distribution, whether ‫they're supported, it will connect in
‫this case, apt to the package manager, ‫with the key to make sure you get the
‫right repository for your install.
‫And then that command runs for a few ‫minutes, depending on how fast your
‫server is, and then you end up here, ‫back at your shell prompt with the
‫Docker command line, the Docker Engine ‫or daemon and a few other utilities.
‫Usually, it comes with some plugins, ‫like BuildKit for building images,
‫Compose for running that, we'll get ‫into all that through the course.
‫So just realize that there's maybe four or ‫five binaries floating around your system.
‫Now, like all the other ways you can ‫install Docker, do a docker space
‫version command, type that command ‫in your shell and you'll should
‫get back at least, the command ‫line client and the server version.
‫When you get back that server ‫version, it means you're able to talk
‫to the server API on that server.
‫If you're on the shell of the ‫server, then it's technically
‫talking to localhost using a socket.
‫I just want to remind you that all ‫that you just did there is open source.
‫The Docker Engine, the Docker command ‫line, all of the plugins there, those are
‫all fully open source, Apache-licensed.
‫Docker Desktop however, from the ‫previous videos, is including all of
‫this stuff, as well as closed source ‫or licensed software from Docker.
‫Docker Desktop is way more of a ‫superset of a bunch of different things.
‫Docker Engine here that we're ‫installing, is just the bare minimum.
‫It's the daemon you need to ‫run a container in Docker.
‫And as a reminder, like I've done ‫in previous videos, if you use the
‫Docker login command, because you ‫only have command line access here.
‫If you type in docker space login, ‫you can log in with your Docker ID
‫and that will get you more pulls.
‫If you remember, pulls are the things ‫from the first few videos in this course
‫that contain the software, you pull the ‫image and then you run as a container.
‫And you do that certain number of times, ‫and Docker may eventually complain
‫and say, Hey, look, you've exceeded.
‫And I think the current ‫number is like 100 in 6 hours.
‫And it says, you've exceeded ‫in the number of pulls.
‫Well, if you're behind a corporate ‫firewall and everyone in your company
‫is all using Docker and they're ‫all behind a single IP address,
‫that limit can be hit pretty quick.
‫But if you simply log in, Docker gives you ‫at least double the amount of pulls for
‫nothing, for free, with a free account.
‫If you pay for Docker, which you ‫don't have to with this course, but
‫if you wanted to pay for Docker, for ‫Docker subscription, you would get,
‫I think, unlimited pulls, as long ‫as you logged in with that account.
‫But let's move on to ‫controlling this daemon locally.
‫Now what's going to happen here, is ‫whatever system you're going to use,
‫let's say, this is a server setup, or ‫it could just be that you don't want
‫to run Docker on your local machine.
‫Maybe you're not allowed to, maybe ‫you can't, maybe you don't have enough
‫resources, maybe you're not root on your ‫local machine, but you do have the ability
‫to run Docker on this remote machine.
‫Well, you don't have to sit in the shell ‫on that remote machine and type all your
‫commands there and do all your source ‫code work there, or clone the repo for
‫this course, you can do nothing there.
‫You can ignore that.
‫You can actually install Docker there ‫and we're going to talk to it remotely.
‫Now let's go back for a second years ‫ago, before this SSH tunnel feature
‫existed, somewhere around 2018.
‫Then before that, you would've ‫had to either ssh into the server
‫and do everything on the server, ‫and that kind of sometimes sucks.
‫Because then you got to copy your ‫stuff over and it just isn't great.
‫You have everything else locally.
‫You have your code editor, maybe ‫you're using Visual Studio Code and
‫you have your source code for this ‫class and you got stuff here, right?
‫So you ideally want to do all ‫that work on your local machine.
‫Docker solved that.
‫When it first came out, back in 2013, ‫the only way we could do that was through
‫a TCP port, which doesn't have built-in ‫authentication, and by default, doesn't
‫provide encryption for the connection.
‫So it was generally considered ‫a bad way to connect to Docker.
‫It was something you only wanted to do on ‫safe networks, and especially because it
‫wasn't authenticated, it could technically ‫allow you remote root access to a
‫server if you just simply connected from ‫anywhere that had access to that port.
‫That's a bad idea.
‫So Docker then added this new feature ‫built-in that we can simply do a
‫transparent SSH connection, as long as ‫you can SSH to that server, and have the
‫authentication or a certificate preferably ‫to SSH into that server, you can do it.
‫And you don't need to jump through ‫hoops or expose any additional ports.
‫So that's what we're going to do.
‫So this step here is to just simply get ‫the Docker command line client on whatever
‫system you're going to be working from.
‫And it can be on Windows, Mac, ‫Linux, Raspberry Pi's whatever.
‫Just get the command line client.
‫If you're on Mac, surprisingly, ‫the brew installer, which if you
‫don't know about brew, you're ‫missing the best installer for Mac.
‫And "brew install docker" ‫doesn't really install the full
‫Docker Engine or Docker Desktop.
‫It only installs the client, because ‫there is no Docker Engine for Mac.
‫Mac kernels don't support containers.
‫So the install surprisingly, only ‫installs a command line, which
‫in this case is what we want.
‫If your local machine was Linux, you ‫could use the Linux install package from
‫Docker's documentation, and then once you ‫have that package set up as a repository,
‫you can then apt install the docker-ce-cli ‫package from that repository.
‫And lastly, if you're on windows, ‫you might have heard of chocolatey.
‫That's one of the package managers ‫for Windows nowadays, and you could
‫do a chocolatey install to install ‫just the command line client.
‫But Docker also has all this ‫explained in their documentation where
‫they tell you how you can get the ‫client libraries for your operating
‫system and just the client library.
‫Okay.
‫The moment of truth, you've installed ‫the Docker engine on a Linux server.
‫Regardless of what you're going to ‫use it for, whether it's just for
‫practice or for real production, ‫you got Docker on the server.
‫You've now got the client ‫installed on your local machine.
‫I should remind you that all those things ‫I just told you about installing the
‫client, if you already have Docker Desktop ‫installed, you don't need to do that.
‫Docker Desktop comes with the client.
‫But we can tell the client where to ‫point where to talk to the server engine.
‫And that's what we're going to now.
‫So imagine I can SSH into a server with ‫something like this command up here,
‫ssh root @ an IP address or a hostname.
‫And let's say I have an SSH certificate.
‫So all of this does assume you ‫understand the basics of SSH, that
‫you know how to get a certificate on a ‫server so that you can log in remotely.
‫There's tons of tutorials ‫out there on that.
‫And that knowledge is assumed again, ‫basic Linux knowledge is assumed
‫before you get involved with Docker.
‫So assuming that we can do that, if I ‫have that access, then all I would need
‫to do is create an environment variable.
‫The Docker underscore host an ‫environment, variable tells the Docker
‫command line which server to talk to.
‫By default, if you just install ‫Docker on something and start using
‫the command line, it assumes the ‫local socket or the localhost.
‫And so it doesn't even have this ‫environment variable, and by default, if
‫it's blank, this environment variable, ‫even though Docker tries to look it up and
‫it doesn't find one, it will say, okay, ‫you must assume that I need to talk to the
‫localhost, and it will do that just fine.
‫But if we change this by adding an export ‫DOCKER_HOST, equals ssh colon slash slash,
‫just like you would use an https URL.
‫So if we replace that with ssh:// username ‫@ hostname, then I can jump in with Docker
‫by just typing regular Docker commands.
‫So notice, I type a docker version ‫here, but I don't have Docker
‫running on my local machine.
‫I just have that Docker client and it's ‫already ssh-ing right over the internet
‫to this remote cloud instance I just set ‫up moments ago, and it returns the server
‫version as well as the client version.
‫If you were to start poking around, ‫you would actually see that I'm on
‫Darwin, which is macOS for my client, ‫and if we scroll down, the server
‫would show Linux because that's where ‫the server is running the engine.
‫And that's it.
‫That's all you need to do.
‫If you want to unset that DOCKER_HOST ‫environment variable, then your Docker
‫command line would revert back to ‫your local machine, assuming that
‫you had the engine running locally.
‫And you can toggle back and forth.
‫In fact, you could have a bunch of ‫different servers and just change the
‫environment variable in each shell you're ‫using, to tell it which server to talk to.
‫There's a Docker context ‫command that can also do this.
‫We won't talk about that yet, that's ‫more advanced for later in the course,
‫but there's technically a built-in ‫command called docker context that
‫allows you to save these settings ‫and manage a list of different
‫engines that you want to talk to.
‫But this one is great to start with.
‫And the last step here is to clone your ‫repository for this course locally.
‫The one that's mentioned a few lectures ‫back in the written lectures, where
‫there's the course repo that you download.
‫You want to put that on your local ‫machine, along with your code editor and
‫everything else, and the Docker client.
‫The only thing that's going to be on ‫the server is the engine we installed,
‫and we're not going to need the SSH ‫into it constantly, because all the
‫Docker commands we run locally, will ‫just execute against that remote server.
‫That remote server, by the way ‫just remember, whenever I'm typing
‫localhost in my browser to test things ‫in Docker, like maybe a website or
‫something that we're running in Docker, ‫you're not going to type localhost.
‫You're going to type the ‫server host name or IP address
‫that you installed Docker on.
‫That's the machine that's running the ‫engine, running your containers, and
‫that you'll need to type in your browser, ‫or if you're running any other local
‫commands, like curl or ping, you're going ‫to need to do those to that server IP.
‫And that's it.
‫You now have an engine running on a ‫Linux server, somewhere in the world.
‫You're running on your local ‫system with your code and
‫your repo and everything else.
‫And you're ready to get started.