I mentioned we were going to talk about networking. And do some networking stuff. So, um, so right now we've run containers that, um, haven't exposed, you know, we haven't had to connect them in any way. So I mostly use containers when I'm doing web stuff. So I need to expose, uh, ports, uh, and, um, and mess with them.
So, uh, I'm going to go ahead and start by running a really simple service. I'm going to use Engine Act. Uh, and so let's go ahead and take a look at Docker hub, um, and see if we've got Engine X there. I mean, I know we have Engine X up there, but I'm being, I'm being overly, overly, uh, obnoxious about it, I guess. Um, probably also helps if I spell Engine X correctly, that's probably important. So yeah, here we go. We've got official Engine X. Um, so we're going to go ahead and use this. This is going to run like a pretty static web server for us, and it'll be running on port 80. Uh, and it'll just give us the like default, like welcome page. So here's what we're going to do. We're going to. Go ahead and do a Docker run. We're going to do the detach again. Dash B detach, uh, and we're going to use dash dash P and what dash P is going to do a capital P here is it's going to publish all the ports and then we're going to do engine X, which again, can I spell it, engine X. Okay. So this is running in the background and we take a look at Docker desktop. We can see that there's an engine in X container running. Um, and we want to go ahead and connect to our web servers. So let's go ahead and do a Docker PS really quickly. Docker PS. And we can see that engine X is mapping my local 5,000, 5,000 zero zero zero to engine X is port 80. So if we go to local hose, um, that's one extra five here. Uh, we can see that this is the welcome page for engine X. So, uh, we've exposed or engine X on the container, and we've mapped that, uh, sorry, this port on my local machine. And we've mapped that to port 80 of the container, which is really great. Um, so we can use local hose to connect into that. Um, and you can also use one 27 as well. Um, two. Um, cool. So let's go ahead and talk about, uh, Finding the, um, so it's possible to like find the address of Docker and, and use that as your IP address. But I think the local host way is a lot easier. Um, and you can also just like, oh, yeah. Two rights, you have Earl, um, you could attach to the thing and then Pearl it too. So, um, so you might be wondering, how did Docker know? What port to. Um. So you might be wondering how to Docker, know what port to, uh, to attached to. And we can go ahead and check that out actually really quickly. We can use this Docker inspect. And let's go ahead and do a help on, docker inspect. We'll return, um, low level templates of, uh, our low level information, a Docker objects. And I'm pretty sure dive. We'll do this too. Um, but we can do it with, with dive maybe instead of, uh, inspect, but this is going to kind of pull the metadata of the image for us, you know, large they get an estimate on how long it is. It should be, it should be fast ish. Okay, here we go. So here is, uh, what is running are layers, and they have it consolidate. Okay. So let's do this. We'll do it with the inspect way. So we can do a docker inspect, docker, inspect, that's Jsh format. And it's going to look for a string. Uh, and it needs this in, in like the go syntax. Um, and we can, we can maybe look really quickly at the docker inspect docs, if it's got some structure of what we pass, so, um, you know, we've got a bunch of, a bunch of things that we can ask. I don't know if it's got a list of. Uh, uh, sample. So here we've got some examples. Um, I'm just going to use, um, uh, dot config dot exposed ports. So this is going to inspect my engine X container. And it tells me that port 80 has been exposed. So that means somewhere in the docker file they've written exposed port 80, um, as well. And, um, I think we can also see this docker history as well. And yeah, and so this is the docker file that they made. So is everything that happens when that engine X files created and you can see right here, they're exposing port 80 so, um, our docker container here only has that one port, um, out, uh, or sorry. So you might be wondering why can't we just connect directly to my local host to AD, right? Um, so my, my Mac book only has one port 84. So therefore if I'm running multiple engine X containers, we're only going to be able to expose one 80 port. So if multiple containers want that port, only one of them is going to be able to get it. And so, um, I default containers just are going to get random ports. Um, In, In like, not like true random, like crypto random, but like just random, like, you know, a bunch of different, different nonsense. And so we can go ahead and actually set that manually. Um, as well. So like what the port number is going to be. So let me go ahead and do a Docker stop and. And X. Um, all right. Docker, yes. Okay. Uh, this ID, uh, and you saw this was really fast as engine X has a built-in handler for, for the sick term. So what we can do is if we want to set this manually, we can do a Docker run, uh, and I'm going to start naming this container as well. So let's do, um, let's look at how we do that. Um, it's going to be where's the name. Off of that order. So yeah. Name string is how we name containers. We're going to do a Docker run, Ash dash name engine X and genetics dash D for detached dash P for publish.
Comments