#100DaysOfWeb in Python Transcripts
Chapter: Days 97-100: Docker and Docker Compose
Lecture: Serving external traffic from Docker

Login or purchase this course to watch this video and the rest of the course contents.
0:01 It seemed like we had our web application basically working. Remember we ran the command HTTP for local host inside the container and it worked?
0:10 But alas, this is what we actually got when we tried to interact with our website from the outside of the container.
0:18 That's because we're not serving the port. So let's go and do that. Now, one of the things we have to type here
0:24 is we have to type docker run and then an image name. Well, what is the latest? What we've been doing so far we say docker build ., and we grab this
0:35 little bit here at the end and go, oh right now it's 80. But if we make a change, then that shaw changes again.
0:43 Make a change, it changes, it's always unstable. So it would be better if we could name this. So we can go over here and we can say
0:49 we're going to tag this. Let's just call this front end and latest. All right, again it's super fast but now it's tagged it, so instead of just saying
0:59 well how do I figure out of all of those which one of those is the one I actually want to run? By the way, it's that one.
1:09 But how do you know if you don't have a name? So now we can do this a little bit better. We say docker, run, let's just go back
1:15 to this IT bit for a minute. And we can say front end, latest, batch. There, now we have a name, we have something predictable.
1:28 And we're going to need this later anyway. So we did things like running Nginx but again we're not going to be able to access this from the outside.
1:41 Instead of just passing this here I want to go over here and I want to give it this command Nginx -g "daemon off;".
1:52 First, let's just see if we can get it to run. It's stuck; what is it doing? Let's open up another thing and say docker ps
2:01 and it looks like it's doing this. Well, it would be great if we could access it. Remember, we've already seen you can't access it yet.
2:10 So let's one more time, let's do a docker stop, I guess, generally? So we'll do an F8 for the beginning of the shaw.
2:18 All right, it echoes out the thing that it did stop and now if we do docker, oops, docker ps, all gone. Okay, and this comes back.
2:28 So what we to do is we need to specify the ports to share. We're going to specify where locally, on this machine on my Mac we're going to list them
2:37 and where on the container we're going to map that to. So we're going to go from port 80 outside to port 80 inside.
2:46 Just like before, everything is running but, check this out. Refresh, boom, it's working. Look at that, that is it running over here.
2:55 It's hard to tell but this is actually the thing we want to be happening. All right, we'll go over here, musical and drama
3:03 you see it's definitely, definitely working. How do we know? Because if we go over here and we say docker ps
3:10 to see what's running, then we say docker stop this is, if we try again that was it, that was our thing running. Now, you saw that it actually had
3:23 all the data in the back-end services because at the moment, it's going to the public one not the one that's part of this container deployment.
3:30 So we're going to adjust that a little bit but how about this? We use the -p port, to map an external port, 80, to an internal port.
3:40 We could do that differently if we wanted but the way Nginx works and the way our local server, our local browsers work that was really what we wanted.
3:50 Okay, so this is how we map external ports and this is how we'd run the server as an external command or as the entry point of our docker container.


Talk Python's Mastodon Michael Kennedy's Mastodon