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 fun!) :)

Tweet ย ย ย  Share
If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue