Docker

Docker

Docker is a platform and technology for building, shipping and running distributed applications. It used containers which are isolated environments that allow developers to package applications with all the necessary dependencies and run them on any infrastructure. Docker makes it easy to manage and deploy applications making it a popular choice for DevOps and software development.

Container

A container is a standalone executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries , environment variables and config files. Containers provide a consistent and reproducible environment, making it easier to develop, test, and deploy applications in different environments. They also allow multiple applications to run on the same host, isolated from each other, which improves resource utilization and security. Docker is a popular platform for containerization, but other platforms like Kubernetes, LXC and OpenVZ also support containers.

Images

A Docker image is a pre-packaged environment containing all necessary files and dependencies to run a piece of software in an isolated container. It is used to create containers for easy deployment and distribution of applications.

Docker Commands

start the docker daemon

docker -d

Display System info

docker info

create and run a container from image

docker run --name <container-name> <image-name>

run a docker in the background

docker run -d <image-name>

start or stop an existing container

docker start|stop <container-name>

Remove a stopped container

docker rm <container-name>

Open a shell inside a running container

docker exec -it <container-name>sh

list currently running containers

docker ps

list all containers.

docker ps -all

Login into Docker Hub

docker login -u <username>

publish an image to Docker Hub

docker push <username> <image-name>

Search Hub for an image

docker search <image-name>

Pull image from Docker Hub

docker pull <image-name>

Build image from a Dockerfile

docker build -t <image-name>

list local images

docker images

delete an image

docker rmi <image-name>

Remove all unused images

docker image prune