From the course: Docker on AWS

From app to containerized app

From the course: Docker on AWS

Start my 1-month free trial

From app to containerized app

- [Instructor] If we want to manage containers in a simple fashion using the ECS tools we of course need to have a container to manage. In our directory here we can do an LS, you can see that in our directory files, we have a simple application that's actually the hostname.shell script, and we can do a more on hostname.shell to look at what our application does real quick. This extends the Nginx web browser by injecting some basic data, an index file that includes an imbedable, versionable host name so we can find out what container we're running and the version itself. We also have a version file, so we can actually just ask the system for a version directly and we have a health endpoint, and this is important when we start looking at scaling the system and scaling the service. We need to be able to query the health of our environment. In this case we're just passing back a simple parameter as well. So with this, we can quickly turn this back into a container, rather than just an open application, an application stub, using the docker file method. We can look at the docker file that we have here by typing more and then Docker file, of course with a capital D, and I'm just going to do D zero and DO and then tab, so more docker file. You can see we have a very simple docker file. We're pulling from the Nginx application, pulling from the standard docker hub environment. We've defined a version parameter that we can both pass in as a build argument or as an environment variable and then we're also pulling in our little host name set up script and running that as the default command. So we can go ahead and build this environment really quick. Just hit docker, build, and the local directory, which is where our docker file is, dash T and we'll tag it with the host name tag. Basic hostname name, and we'll give it the latest tag as well. So this will take just a second to build, and the next binary is actually fairly small in terms of a base container. Now we have our environment, and we can go ahead and run it if we do a docker run pass RM to clean up after ourselves, give it a name that we can capture easily, name, will give it just name of test, it's simple. We also do want to demonize this, which means we want want the container to run the background for us, and we're going to tell it what container to run which was the one we just built, which was hostname, not test, hostname latest, the latest version of the hostname binary, and before I forget, we do need to pass the port because we are actually wanting to talk to this container so we have to tell it which port to pass. Since we're doing this locally, we're going to say pass in port 8080 and we'll map it to the internal port 80 which is where the Nginx server runs. So if we run this, and then we can use pearl command to go and query this http://local host on port 8080, it's colon 8080, and we should get the webpage back. As I said, there are a couple of other endpoints that we have with this particular application as well, so I'm just going to hit the up arrow and I'm going to add in the version output, version, and then the slash, these are directories so they're not as simple as some of the controller that you might be using otherwise, but we do get the V1 version, and we can also check the health endpoint just to make sure that we're getting all the outputs we would expect to get. Health, health, spell that as health with a Z, and an output there, and we see that we're getting healthy. So this lets us know that we have a little application that we can build and leverage for the rest of the coursework and again, we're going to use this as an application that we're going to deploy into the ECS environment.

Contents