Docker, testing the waters
Let’s cut the crap, I can’t think of a good way to start this shit, you know brain dead hours. Let’s just jump right into it. Yeah you clicked on it, you already know the topic of todays article, Ladies and gentlemen, it’s the cool-guy-hero of the software development world, I present you Docker!!
First thing, Installing Docker. Follow this link, Download the file, Install, Run the application. All cool? Got it all? Let’s move on.
Note: We have to keep docker desktop app running in the background every time we use docker, even when using it on terminal. So make sure it’s running before anything else.
We can use a version check to see if we have successfully got docker installed. If we get a version, it’s good to go, otherwise we have messed something up.
docker --version
Got an output with the version and some code kinda thing called build, don’t know what that is, Ah! Maybe it’s not that important. At least we know we got docker installed. Guess we haven’t messed it up. I mean… Yet!
Next, Imma try to get an nginx image from the docker hub and run it on local machine. I don’t know man, this whole docker and docker hub model is a freaking rip off of git and GitHub. I mean, look, In docker hub we have repositories, just like in GitHub, but these repos only contain images of apps, not the entire code, And when we need to get an image what do we do, we pull from docker hub. And when we require to put an image to docker hub what do we do? Yeah you guessed it, we push. Plus the damn thing is called docker “hub” for gods sake. Not complaining just pointing it out, it’s easy wrap the head around it this way, same concept.
Okay, Time to pull.
docker pull nginx:latest
Now we can check if the command worked properly by running a simple docker images
command. Then we get an output like this with a table showing details about all the docker images we have pulled. Or created by ourselves, Imma try creating part too. But for now the focus is on somehow getting this naked nginx image running on ma local machine.
Okay now we got the image let’s move on and run a container using this image.
We can use docker container run
command and then specify the name, port and the image that we are gonna use. Lemme show you real quick how it’s done.
docker run -d --name test-nginx -p 3000:80 nginx:latest
Run docker ps
command to see the details of running containers.
And that’s it, now if we visit localhost:3000 we get this beautiful nginx homepage, indicating that it works.
Hey, You wanna know what actually happened just as we smashed the enter after typing run command? When we create a docker container using an image, it’s gonna create a whole new machine inside the container, the image is like a blueprint on how to create the container, which works just like a virtual machine but better, faster and lighter. All we need is to give it name and a port to be exposed at, it does all the magic and creates new container.
By putting that -p 3000:80
we ask docker to map the port 3000 of our local machine with the 80 port in the created docker container. So when we navigate into localhost:3000
we get to access the :80
port of our pretty little isolated container and then by putting -d
we ask docker to keep the container running in the background.
Just think, one single command, wait for 2 seconds, bam!! You get a whole new machine setup inside your local machine, completely isolated and configured to run the defined application in the image, with all the necessary resources boiled into it. Dude… I mean… it’s crazy right?? That’s some next level shit I tell ya, whoever made this piece of wonderful tech is a freaking GOD!!!.
That’s it for this one folks, and as I promised Im gonna write the next one on creating our own docker images, so stay tuned people. bye, bye!!