View profile

But it works on my machine! ๐Ÿคทโ€โ™‚๏ธ

But it works on my machine! ๐Ÿคทโ€โ™‚๏ธ
By Apoorv Tyagi • Issue #4 • View online
Welcome to the fourth issue ofย The Trojanโ€™s Wednesday Wisdom newsletter.ย I hope you all had an amazing last week.
Today letโ€™s talk a little about Docker ๐Ÿณ
Iโ€™ll be sharing some common terminologies and useful commands that will help you get started with it.
So get a cup of coffeeโ˜• and let us begin

What is Docker?
Have you heard of this famous phrase,ย โ€œIt works on my machineโ€?
In simplest term, this is the problem that Docker solves.
Docker makes it easier to build, deploy and run applications using containers.
Containers, which is a standard unit of software allow us to package all the things that our application needs, such as libraries and other dependencies and ship it all as a single package.
In this way, our application can run on any machine and have the same behavior.
FUN FACT - The whaleโ€™s name in Dockerโ€™s logo is โ€œMoby Dockโ€ ๐Ÿ‹
Terminologies
  • Imagesย are the blueprints of the application which form the containers. Youย docker pullย an image.
  • Containersย are created images. They run the actual application.
  • Dockerfile ย is a simple text file that contains a list of commands that the Docker client calls while creating an image.
  • Docker Hubย is a registry of Docker images.
  • Daemonย is the background service that manages the containers.
Useful Commands
docker run [IMAGE]
Pulls and runs image.
  • docker run -itย to run interactive
  • docker run -it shย to run shell commands inside container
  • docker โ€“rmย removes the container once run
  • docker โ€“detatchย will let container run in the background
  • docker image prune -a to delete all images
  • docker โ€“publish-allย will publish all exposed ports to random ports
  • docker run โ€“port 8000:80ย to specify a custom port. Ports are in the format ofย LOCAL_PORT:DOCKERFILE_PORT
docker push [IMAGE]
To push Docker image to Docker Hub.
docker build
Build docker image.ย 
  • docker build โ€“tag username/project-name . ย to add tag name
Containers
  • docker start [containerID] to start a container
  • docker stop [containerID] to stop a container
  • docker ps โ€“allย to list all containers
  • docker ps to list all running containers
  • docker exec -it [containerID] [filename] to explore files inside a container
  • docker rm [containerID] to delete container.
Now, If you want a more hands-on tutorial on Docker, I have written a nice article on that too.
๐Ÿ“ƒIn the blog post below, I have shown how you can containerize your application and even get it running on Kubernetes (Which is a famous container orchestration tool).
The theoretical introduction that I just gave you is enough pre-requisite for this tutorial.
This is how the roadmap looks like.-
  1. We create one simple application.
  2. Containerize our app by creating an image using Dockerfile.
  3. Finally deploying everything on kubernetes.
(You can leave the last step if youโ€™re not very comfortable with Kubernetes).
Containerize your web application & deploy it on Kubernetes
Finishing what we left last week ๐Ÿ•š
In last weekโ€™s newsletter, I have shown you this image and asked you to identify the bug in the code ๐Ÿ’ป
So were you able to find out whatโ€™s wrong?
The best part here is that only one character fixes this code and guess what it isโ€ฆ๐Ÿค”
A semicolon(;) ๐Ÿคฆโ€โ™‚๏ธ
Just by inserting a semicolon after our first function ends, It will work, and youโ€™ll see โ€œHello World!โ€ in your console.
But Why? ๐Ÿคฏ
Because without that semicolon, the last function is interpreted as an argument to the first function call.
Hereโ€™s a rewrite that demonstrates whatโ€™s going on when the code is run without the semicolon ๐Ÿ‘‡
There are 3 function invocations in that last line:
  • f1ย is called with no arguments.
  • The return value ofย f1()ย is called withย f2ย as its argument.
  • The return value ofย f1()(f2)ย is called with no arguments.
Since the return value ofย f1()ย is not a function, the runtime throws aย TypeErrorย during the second invocation.
With the semicolon added, this becomes ๐Ÿ‘‡
Which now runs as expected๐Ÿ™‚
Moral Of The Story - โ€œAlways use semicolonsโ€
Relying on Automatic Semicolon Insertion(ASI) is not encouraged, This is even included inย Googleโ€™s,ย Airbnbโ€™s, andย jQueryโ€™s Javascript style guides.
Thatโ€™s it from my side for this week. I hope you enjoyed what I included this time and have learnt something new๐Ÿคž
๐Ÿป Consider subscribingย in case you havenโ€™t already and share this newsletter with those you feel can get benefit out of it.
๐Ÿ‘‹ See you on the Internet next Wednesday!
-Apoorv;
Did you enjoy this issue?
Apoorv Tyagi

๐Ÿ“ฉ ๐—” ๐—ป๐—ฒ๐˜„๐˜€๐—น๐—ฒ๐˜๐˜๐—ฒ๐—ฟ ๐—ฎ๐˜ ๐˜๐—ต๐—ฒ ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐˜€๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐—ผ๐—ณ ๐๐ฌ๐ฒ๐œ๐ก๐จ๐ฅ๐จ๐ ๐ฒ, ๐๐จ๐ง-๐…๐ข๐œ๐ญ๐ข๐จ๐ง ๐๐จ๐จ๐ค๐ฌ ๐—ฎ๐—ป๐—ฑ ๐’๐จ๐Ÿ๐ญ๐ฐ๐š๐ซ๐ž ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ๐ข๐ง๐ .

๐๐จ, ๐ฐ๐ž ๐๐จ๐ง'๐ญ ๐œ๐ฅ๐š๐ข๐ฆ ๐ญ๐จ ๐ฆ๐š๐ค๐ž ๐ฒ๐จ๐ฎ ๐ฌ๐ฆ๐š๐ซ๐ญ๐ž๐ซ ๐ž๐ฏ๐ž๐ซ๐ฒ ๐ฐ๐ž๐ž๐ค. ๐Ž๐ง๐ฅ๐ฒ ๐ฌ๐ฎ๐›๐ฌ๐œ๐ซ๐ข๐›๐ž ๐ข๐Ÿ ๐ฒ๐จ๐ฎ๐ซ ๐ข๐ง๐ญ๐ž๐ซ๐ž๐ฌ๐ญ๐ฌ ๐š๐ฅ๐ข๐ ๐ง ๐ฐ๐ข๐ญ๐ก ๐š๐ง๐ฒ ๐จ๐Ÿ ๐ญ๐ก๐ž ๐ญ๐ก๐ซ๐ž๐ž ๐ญ๐ก๐ข๐ง๐ ๐ฌ ๐ฆ๐ž๐ง๐ญ๐ข๐จ๐ง๐ž๐ ๐š๐›๐จ๐ฏ๐ž!

P.S. It is free (and probably fun)

Tweet ย ย ย  Share
In order to unsubscribe, click here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue