Article originally written at https://jayachandrika.com
In this Article lets explore :
Have you ever built an application but it doesn't run on all platforms? Or been sick of installing different dependencies and libraries for each service/component in the application? Dodged the whole nine yards just to deploy, scale and manage a simple application??
Then DOCKER is waiting for you!!!
Docker:What the hell is it?
Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers.
(Well. . .thats the GOOGLE definition for you! )
To wrap it up simply,it is just a BOX!
Imagine,
A printer box, we insert a paper and get printed text or colors on it.
So how is it working ? Perhaps all the colors and required material is already present in the printer.
Consider a car wash, car is sent in, many process like washing, cleaning etc happen and at the end we get a shiny clean car (or a less rusty one).
So, docker is like a printer box or car wash setup in this instance, taking an input
and giving an output
basically.
It is basically a box with an application and its related dependencies, libraries etc inside it
But why docker?
Imagine we are building a zoo, we toss all animals like monkeys, Lion and Crocodiles in one big park with only one kind of food and only one kind of environment, lets say, land.
The bananas eaten by monkeys can’t be used by Lions and crocodiles, the meat for Lions can’t be eaten by monkeys. Monkeys want trees and crocodiles need a water space in the environment.
In similar way, if we are building an application that has services like a database and framework etc, The libraries and dependencies(food) used by databases (cassandra, postgresql, mongodb etc) may not be compatible/suitable for frameworks (strapi, nodejs express etc).
Eg: MongoDb version 4.26 might not be compatible/suitable for NodeJs version 4.16.4
To make it easy to develop, run and maintain an application and to operate on all the platforms we came up docker. The problem in zoo example can be solved by providing each animal, a separate boundary with the required food and environment.
Containers
In docker we have those separate boundaries called containers. We place each service in one container with all the libraries and dependencies required for it.
Container is a completely isolated environment with their own processes, network interfaces and their own mounts.
Wait, doesnt it look familiar? Yes,you are right if you guessed it, they remind us of Virtual machines. If its similar to VMs, Why on Earth do we need to use Containers??
Well, Each VM has a separate OS along with libraries, dependencies and application, which increases overload and utilization, making it difficult to operate it in small PCs(though we might not use it there).
Whereas Containers share the same OS, considerably less overload and utilization than VMs. Hence they are just the darlings preferred for application development, deployment and management.
Images
These are readymade templates of services like MongoDb, NodeJs etc, to run in containers. We can either use existing images from docker.io or create our own.
Creating an Image of the service helps in shipping it for deployments. Then it is just running a simple command to get the server up and running. We dont have to worry about creating environment, installing dependencies and what not.
Magic commands
Its time to blow some fairy pixel dust and do some magic!
Lets start with running an image in a container,using run command.
Run redis image in container
docker run redis
List the version details
docker version
List the Running containers
docker ps
List the Running & Not Running containers
docker ps -a
Remove a container
docker rm [container ID]
Note: To remove a container make sure it is stopped first using stop command.
List the images
docker images
Remove an image
docker rmi [image_name]
Just download the image but not run in the container
docker pull [image_name]
Thank you so much for reading my content. More of such content coming on this blog, so stay tuned.
Article originally written at https://jayachandrika.com
Top comments (49)
docker stop 6f
can I identify container just by first two symbols???
Very good question.As long as any other container doesn't start with 6f, you can use 6f. Suppose container A has id '6fedstk' and B has id '6fesyiu', you have to choose atleast 6fed to represent A, to make them distinguished
Hope it was clear. Do ask for more doubts😄
it doesn't work for me :(
May i know the container id names and the command you used?
yes, sure ibb.co/pQXXgZX
Try docker stop fdd
Let me know what happens
Try docker stop fdd
Let me know what happens
it seems that's my bad. I'm terribly sorry.
it doesn't work for the whole container ID as well
those containers just were not started
I thought the error message will be slightly different, like 'the container is not started yet'
Glad you found the solution 😄
here is the screenshot from console ibb.co/pQXXgZX
Didn't know that. Thanks for letting us know ma'am 👍
Good one...
You can use the #devops tag to your post, it is very relevant to devops. 🙂
yeah
Thank you for the suggestion 😊
correct
Nice
Glad you found it useful 😄
Well I’m just starting with Swift Server side, so yes you had the practical examples spot on!
That's cool. Best of luck!
That's a beautiful post. Loved the way you created a relation between real life and docker✨
Very happy that it was interesting to you Mr.Trideep
Docker seems interesting. good article btw
Glad you enjoyed it Mr.Venkat☺️
Amazing article! Looking forward for more! Keep going.. 🙌
Thank you for the support 😄
Helpful
One of the best articles I've read on Docker, seriously.
You explained the concept and implementation in such easy and interesting way.
Kudos!
~Akshat
Thank you very much for the encouragement 😄
Tha was very useful. Thanks for sharing
Glad it was helpful to you 😊
Greatttttttt!!!!!
Thank you ☺️
Actually I use docker almost everyday but without knowing some of the facts you explained. Thanks for this great article.
Glad you find it useful 👍😊
Nice Article Ms Reddy.
1) Docker is challenged by podman on security. Google for podman. Podman and docker have same commands and you can use docker hub too.
2)dev.to/manishfoodtechs/5-minutes-c...
Thank you manish! Read your article, its good and engaging 👌
Yes, but podman is rather niche still. Someone reading a beginner's article like Jaya's is not going to be ready for podman.
Agree with Ben. While Podman has it's benefits over Docker it's a part of RedHat ecosystem. Also given that majority of the dev's have adopted/migrated their applications to docker there's a less of a chance they're going to shift back to a completely new product like Podman.
Yes Mr Aggarwal & Mr Ben .
A new learner may go for docker. But in future he has to adopt the new technology Podman which is more promising than docker.
Podman is niche technology why to try?
Since, both ( docker and redhat are OCI member , so system admins have no reasons to worry. Also , Amazon Fargate (AWS Fargate), OpenSUSE, Openshift, centos, oracle and RHEL all in latest release have dropped Docker. More and more companies are dropping docker and so system admins.
what is the problem with Docker? Actually there are few,
-A single process could be a single point of failure.
-This process owned all the child processes (the running containers).
-If there is any failure in the docker daemon, then every child processes are lost its track.
-Building containers led to security vulnerabilities.
-All Docker operations had to be conducted by a user (or users) with the same full root authority.
I use LXC & LXD and create my own secure environments. However, I don't hesitate to learn other technologies like docker or podman. What I know, More and more companies are shifting from "running Docker" to "running containers" and adapt new tools, all of which are standard-compliant and even work nicely with one another.
Here comes the role of podman which solves most of the problem.
Hi sir, where can I learn more about Podman? 🙂
Podman is very easy if you know how to do basics of docker you know basics of podman. Commands are similar. Just you have to remove docker in command with podman. Like docker pull will be podman pull and docker run will be podman run....
To quickly learn docker here is an article of mine:
dev.to/manishfoodtechs/5-minutes-c...
Thank you so much sir. It was glad receiving reply from you, will check your article out now. 🙂
I agree with your assessment of the problems with Docker.
I'm not saying that podman is bad. I'm saying that it has no place in a beginner tutorial for Docker.
while Podman is promising and maybe devs will eventually shift to Podman or something new. But that shift isn't happening overnight or anytime soon is what I am saying.
If I would need to use a script outside the container that executes a bash command inside the container using the default user, what's the best practice?
33 is macOS default user id
1000 is Linuxs
and windows can't even use .sh files
The reason behind this is cus the application environment is configurated on the named database container, meaning we cant run commands outside the container as it would imply the settings are wrong.
great breakdown, thank you!
Thank you for the support😄
dev.to/manishfoodtechs/time-to-say...
TIME TO SAY BYE BYE DOCKER
Some comments have been hidden by the post's author - find out more