Learn Docker in 2 minutes
What is a Docker?
- Its just a way to package a software so it can work on any hardware.
- Inorder to understand how that process works, you must know this 3 key things:
1. DOCKERFILE - A docker file is a blue print for building a docker image.
2. IMAGE - A docker image is a template for running container.
3. CONTAINER. - A container is just a running process.
Installing and tooling :
- If you are on MAC or Windows you can install "Docker Desktop" application. It supports both GUI and CLI.
docker ps: - it gives you list of all running containers.
- install Docker extension for vscode or your IDE: This will give you language support when you write docker files. Also link up to remote registries and bunch of other stuffs.
The DOCKERFILE:
- which contains code to build your docker image and ultimately run your app as container.
The Docker IMAGE:
- You build docker image using docker build command: docker build -t sbs/myapp:1.0 .
The CONTAINER:
- docker run b904506d737c
- port forwarding: docker run -p 5000:8080 b904506d737c
NOTE: when you stop container any state or data inside it will be lost. But there can be situations where you want to share data across multiple containers and preffered way to do that is with volumes.
DOCKER VOLUME:
- Volume is just a dedicated folder on the host machine and inside this folder a container can create files that can be remounted into future containers or multiple containers at the same time.
- command: docker volume create shared-stuff
DEBUGGING:
- docker exec -it 8086a* /bin/sh
NOTE: one of the best things you can do to keep your containers healthy is to write simple maintainable micro-services. Each container should only run one process. And if you need multiple processes then you should use multiple containers and docker has tool just for that called docker compose.
DOCKER COMPOSE:
- Its just a tool for running multiple docker containers at the same time.
- commands:
- docker-compose up
- docker-compose down
Useful Commands:
Docker Official page for commands
Uninstall docker on linux (RHEL, CentOs):
yum remove docker
rm -rf /var/lib/docker
Problem statement of Docker:
- "It works on my machine and not on others".
Docker is compatible with any program
- Container is a heart of docker.
- Portability - key feature of docker
- Allows social containers.
- docker is a software that allows you to create containers.
Summarize:
1. Client side application program. - you can just install docker & it can does all things for you. Including designing container for you. All of your code and config would be packed.
2. It can also act as service. and can be deployed on any server.
3. It can also act as social networking platform. Just like anything you can share docker images.
Delete all images : docker image rm $(docker images -a -q)
Comments
Post a Comment