Consistent Environment: It ensures that your app runs the same way everywhere, whether on your laptop or a server, because Docker packages everything it needs (like code, libraries, etc.) into a container.Easy Setup: Developers can quickly set up and run apps without worrying about installation issues (e.g., missing dependencies).Isolation: Each app runs in its own container, so if one app crashes, others are unaffected.Scalability: Docker makes it easy to scale your apps up or down based on demand by creating more container instances.Efficiency: It uses fewer resources than virtual machines (VMs) because containers share the same operating system, making them lightweight.Where can we get packages from?
Just like you can push your code to Github/Gitlab.
You can push images to docker registries
Docker Hub: The main public repository for Docker images. You can find a wide variety of pre-built images for popular software like Node.js, MongoDB, PostgreSQL, etc. Simply pull an image using:
Private Repository : If you're working in a company, you might store Docker images in a private repository. Docker Hub allows private repositories, or you can use alternatives like:
AWS Elastic Container Registry (ECR)
Google Container Registry (GCR
Azure Container Registry (ACR)
You can create your own Docker image using a Dockerfile that specifies the dependencies and setup for your app. Build the image with:
docker build -t <your-image-name> .
GitHub Packages: You can store Docker images in GitHub's package registry, useful for integrating with your CI/CD workflows.
Common commands to know 🔥
Pull an image from Docker Hubexample:
List all downloaded images:Remove an image:Run a new container (detached mode):docker run -d --name <container-name> <image-name>
example:
docker run -d --name my-app node
List all running containers:List all containers (including stopped):Stop a running container:docker stop <container-name>
Remove a container:docker rm <container-name>
Restart a stopped container:docker start <container-name>
Enter a running container's shell:docker exec -it <container-name> /bin/bash
These commands will help you navigate Docker from basic usage to more advanced operations. Keep this cheat sheet handy as you work with Docker! Happy coding! 🚀