- In a previous video in my WSL series, I showed you how to get
Docker up and running on WSL version two on
a Windows 10 computer. But I had a lot of questions like, "David okay, so I've got Docker running within WSL, but what can I use it for? Can you give me some practical examples." So in this video, I'm gonna show you how to pull Docker containers and launch multiple websites
within Docker containers on Ubuntu, running within WSL version two, running on a Windows 10 laptop. I'm doing everything on this laptop, but I'm controlling the
laptop using VNC from my Mac. That just makes it easier
to do the recordings, but I am doing everything
on this Windows 10 laptop. Okay so without further ado, lemme show you how to
pull Docker containers, how to launch a website within Docker, running on Ubuntu within WSL version two. (upbeat music) In this example, I've got
windows terminal installed, so I've got PowerShell running here. If I tap WSL -l -v, I can see I've got multiple
virtual machines running within WSL version two, such as Ubuntu, as well as Kali or Kali Linux. This is my default virtual
machine within WSL version two. I'll launch the Docker dashboard. And as you can see here, I've got a whole bunch of
Docker containers downloaded. Now I've previously downloaded some of these Docker containers. Don't worry if you don't have them. The great thing about Docker is that if you try and start a Docker container and you don't have it locally, it'll automatically do a pull from Docker and download it, install
it and start it up for you. So Docker makes it very
simple to share applications because everything is contained
within this container. Makes it very simple to start
new applications on your PC. If I go to settings, under general, you can see that I'm
using WSL version two. I'm using windows Home here, so that's the only
option I have available. Under resources, WSL integration. You can see I've got Docker enabled on these two Ubuntu virtual machines. It's also enabled on
the default WSL distro, which is actually Ubuntu 20.04. So on my Ubuntu 20.04, Docker PS shows me that I've got no Docker
containers currently running. So I've got Docker installed, but no containers are currently running. So as an example if I go to localhost, now this is running within
windows and go to port 8080. Nothing will happen, this will time out because I don't have a web server running on port 8080 on my local computer. No web service currently
running on that port. But what I'm gonna do is I'm gonna start a Docker container. I'm gonna map port 8080 on the outside, to port 80 on the Docker container. So when I connect to port
8080 on my localhost, it's gonna map to port 80
on the Docker container. The Docker container has
a web server running. I'm gonna start the getting
started Docker container. So that's now running. If you don't have that running,
it'll do a Docker pull. So you might see some different output to what I've got here. I've previously downloaded this. So just started locally but if
you don't have it installed, it'll pull it and then start it. So if I type Docker PS, you can see that this Docker
container with this name is currently created and running. This port is mapped to port
80 on the Docker container. So, go to my browser and notice
the website now displays. This is a command that you could run which is very similar to what I've run. And you told that d runs the
container in detached mode. In other words, runs it in the background. P allows me to specify the port. In my example, I used
port 8080 to port 80. Rather than what they did here of mapping port 80 to port 80. And this is the image that they are using. So as an example, lemme copy that, and I'll paste that in. Notice it says, "Unable to find this image locally." So it's pulling that image. So Docker PS, I've got two images running. So, localhost, port 80. And I don't even have to
put the port number in because the default is port 80. Notice I've got a Docker
container running on port 80, and I've got a Docker
container running on port 8080. I've got two Docker containers
and now up and running within WSL version two on
my Windows 10 computer. So back in PowerShell, WSL -l -v. Notice I've got this
virtual machine running within WSL version two. Here's that virtual
machine and at the moment I've got two Docker containers running. So let's start another Docker container. So what I'll do here is
start an nginx website. I'm gonna give it the name, my website. The port number that
it's gonna use is 8081. So at the moment, if I go
to the localhost, port 8081. This will time out because I don't have anything running on that port. So notice connection has refused. But if I start that Docker
container, it's now running. So Docker PS shows me that I've got three Docker containers running. Here's the newest one. I'll refresh that page and notice I can see that a website is available. Now this is very basic,
you'd have to edit to this if you wanted it to do something. But ngnix is a very popular way of hosting websites today. Give you a lot of powerful functionality. So you can have a look at their website as an example to get details. But I am running that
website on my local computer. So these are again, websites running within a Docker container,
running within Ubuntu 20.04, running within WSL
version two on Windows 10. Okay so let's start another one. In this case I'm gonna
run Tetris on port 8082. So, localhost, port 8082. Again this will timeout, because I don't have anything
running on that port number. What I'll do is keep
that in the background and I'll stop this. So that's now started and notice, you can see the page in
the background refreshed and something's happened. So Docker PS shows me I've
got four websites running. I can press space bar and
now I can play Tetris, if I wanted to. So I can decide where
to put my Tetris blocks. I won't bore you too much
'cause I'm not great at Tetris. But as you can see here I've now got an additional
website running. In this case It's Tetris, as the functionality within Docker. The port number used here is 8082. Port 8082 is mapped to
port 80 on that web server. And there it's running. Now I could stop my Docker containers. So if I type Docker, I'll see various options, and one of them is stop. So Docker PS again shows
me my Docker containers. I'll copy the Tetris
Docker container and type. "dockers stop," right-click to stop that Docker container. So Docker PS, notice that Docker container is no longer running. And if I refresh this, what you'll notice is my
Tetris game will no longer work because I've stopped at
that Docker container. The same with nginx,
it's currently running. But if I stop this Docker container. So I'll copy that, right-click. That is now stopped. So if I refresh this
connection to port 8081, it will no longer work. Now you may wonder, where do you get these Docker containers? So if you go to hub.docker.com, you can search for different
types of Docker containers. Here's the Oracle Database
Enterprise Edition. Here's Ubuntu. There's a whole bunch of Docker containers that you can download. So let's do Ubuntu within Ubuntu. Now if I wanted to pull
this Docker container, I would use the command,
"docker pull ubuntu." But what I'm gonna do is
I'm actually gonna run it and open up a bash shell. Notice how the prompt changed. Lsb_release, doesn't work in this Docker container. But if I exit, I've exited from the Docker container into my Ubuntu virtual machine, running within WSL version
two, and the command works. This software is installed in this Ubuntu, but it's not installed in this Ubuntu. If I run that again and
go cat/etc/os-release, you can see that this is also running Ubuntu 20.04, within Docker. So I've got Ubuntu within Docker, within Ubuntu, within WSL version two on a Windows 10 laptop. You could pull many types of
Docker containers from here. There's many of them. Here's httpd. I've already demonstrated ngix. You could also run Docker within Docker. Many, many options available here, and I won't bore you with all of them. Let me just show you once again Tetris. I'll go out of my Ubuntu Docker container. Docker PS shows me that I've only got those two running. Again port 8080 doesn't work
because I haven't started up my Tetris Docker container. I'll make this smaller. Press enter now, it's booted up and this will hopefully connect, and there you go. I can press space bar
and start playing Tetris, on a Docker container within Ubuntu. Okay so that was a practical example of showing you how to
get Docker containers. How to pull them and
run them within Ubuntu, running within WSL version
two on a Windows 10 laptop. Now hope you enjoyed this video. If you did, please consider subscribing to my YouTube channel. Please like this video
and click on the bell to get notifications. I'm David Bumble. I wanna wish you all the very best (upbeat music)