Docker

Docker is an open-source platform that automates the deployment, scaling, and management of software applications inside containers. Containers are lightweight, portable, and self-sufficient environments that encapsulate application code, runtime, system tools, libraries, and settings, enabling applications to run consistently across different computing environments, such as development laptops, on-premises servers, and cloud platforms.

Docker Image

A Docker image is a lightweight, standalone, isolated executable package that contains everything needed to run a piece of software or application, including the code, runtime, libraries, environment variables, and system tools. Docker images are created using a declarative file called a Dockerfile, which specifies the instructions for building the image layer by layer.

Docker Registry

A Docker Registry is a repository for Docker images

Free Docker Registry List:

Docker Command

Command Function
Docker version Check Docker Version
docker image ls Show docker image
docker image rm Delete docker Image
docker build Build Docker
Docker pull redis:latest Download Docker
Docker run Run docker
id -nG Check Group docker
sudo usermod -aG docker username Add user sudo into docker
docker docker-subcommand --help
docker search ubuntu Search docker image
docker pull ubuntu Download docker image
docker images see downloaded image
docker run -it ubuntu Run container
docker ps Check active container
docker ps -a Check all container
docker ps -l Check latest container
docker start 1c08a7a0d0e4 Run container (with ID)
docker stop 1c08a7a0d0e4 Stop container (with ID)
docker stop quizzical_mcnulty Stop container (with Names)
docker rm 1c08a7a0d0e4 Delete Container (with ID)
Docker create --name containername image:latest Create continer
Docker create --name contohredis redis:latest Create a redis container from redis docker image

Container Log

Command Function
Docker container logs containerid or namacontainer Debuging log
Docker container logs -f containerid or namacontainer Realtime Debuging log.

Container Port / Port forwarding

When running, a container use specific port inside on the container. To acces the port running inside the container, you will need to forward to port. This specific 8080:80 format meaning that the contianer use 80 port and it’s being forwarded to use 8080 on host machine. Format:

Docker container create --name namacontainer --publish posthost:portcontainer image:tag

Example:

Docker container create --name nginx --publish 8080:80 nginx:latest	

Container Stats

To monitor the CPU and memory usage by docker container

docker stats

By default container use all CPU and Memory resource available on a machine. To limit the resource use the following format:

Docker container create --name smallnginx --publish 8081:80 --memory 100m --cpus 0.5 nginx:latest