Docker, Docker Compose and its important commands!!
What is Docker??
Docker is a package management tool that allows you to build, package and deploy your applications. With docker, you can test, ship and deploy your code. With the help of docker, you can package your applications.
- It provides fast consistent delivery of your applications.
- lightweight and fast.
Images:
It is a read only template of instructions for creating a container. For example, ubuntu image.
A container image is a standardized package that includes all of the files, binaries, libraries, and configurations to run a container.
Containers:
It is a running version of an image. You can start, delete, or stop a container by using Docker CLI.
For example:
docker run -i -t ubuntu /bin/bash
Some important commands of Docker:
- docker login : for login purpose
- docker images: list available images
- docker ps: provide all running containers.
- docker ps -a: provide all hidden and running containers in the system.
- docker exec -it container /bin/bash: run a command in a container.
- docker run: run a image from registry.
- docker logs container: provide logs of a specific container.
- docker restart: restart a container.
- docker inspect: display information about a container.
- docker network create: create network.
- docker network ls: list available network.
- docker image prune: removes all images.
- docker system prune: removes all stopped containers.
Container vs Virtual Machines:
VM is an entire operating system with its own kernel, hardware drivers, programs, and applications.
Container is a process with all of its files to run.
Finding images
- Docker Hub is a service provided for finding and sharing container images.
- Docker Hub is the default global marketplace for storing and distributing images.
It has over 100,000 images created by developers that you can run locally. You can search for Docker Hub images and run them directly from Docker Desktop.
Docker Hub provides a variety of Docker-supported and endorsed images known as Docker Trusted Content. These provide fully managed services or great starters for your own images.
Docker Compose:
It is a software tool for defining and running multi container applications.
Compose simplifies the control of your entire application stack, making it easy to manage services, networks, and volumes in a single, comprehensible YAML configuration file. Then, with a single command, you create and start all the services from your configuration file.
Some important commands of docker compose:
docker compose up -d
docker compose version
docker compose down
Dockerfile
Every Docker container starts with a simple text file containing instructions for how to build the Docker container image.
Dockerfile automates the process of creating Docker images. It’s essentially a list of CLI instructions that Docker Engine will run to assemble the image. The list of Docker commands is vast but standardized: Docker operations work the same regardless of contents, infrastructure or other environment variables.