/Docker-basic_commands

The repository demonstrates how to containerize machine learning (Here, we have implemented basic image conversion to grey scale) applications using Docker, making it easy to package, deploy, and run them consistently across different environments.

Primary LanguagePython

The repository demonstrates how to containerize machine learning applications using Docker, making it easy to package, deploy, and run them consistently across different environments.

Docker Overview

What is Docker?

Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. Docker simplifies the process of managing and scaling applications, improving efficiency and collaboration in software development.

Docker image

A Docker image is a lightweight, standalone, and executable software package that contains everything needed to run a piece of software, including the code, runtime, system tools, libraries, and dependencies. In simple words, it is a screenshot of entire program.

Container

Containers are isolated environments that include the application and its dependencies, making it easier to ensure consistency and portability across different systems. In simple words, it is an environment where the images will be exceuted.

Docker Hub

Docker Hub is a service provided by Docker for finding and sharing container images. There are Private repository too.

Docker vs Virtual Machine

Both are used for virtualization.

image

Docker - virtualize only application layer, smaller size, faster, Host OS dependent.
VM - virtualize both application layer and OS kernel, larger size, slower, Host OS independent.

Dockerfile - Building our own Docker Image

Blueprint for building image. It has separate syntax such as FROM, ENV, COPY, RUN, EXPOSE, CMD and More. The file name should be in a standard format like "Dockerfile".

Docker Compose - Running multiple services

Compose is a tool for defining and running multi-container Docker applications. With Compose, we use a YAML file to configure our application's services.

Docker Volumes

Data generate or used by the container will be deleted once the container is stopped. Docker volumes are a way to persist data and it is separate from the container's lifecycle.

Docker Network

Used for creating communication within the images in the container.

Docker Commands used

To build a Docker image from a Dockerfile:
docker build -t [name]:[tag] [location of Dockerfile]

To run a Docker image in detached mode:
docker run -d -p[host port]:[contianer port] [name]:[tag]

If an image is already built and ran at least once, we can rerun the image using::
docker start [docker container id/ docker image name]

To stop the execution for Docker image:
docker stop [docker container id/ docker image name]

To see the logs of the Docker image:
docker logs [docker container id/ docker image name]

To delete container:
docker remove [docker container id/ docker image name]
docker rm [docker container id/ docker image name]

To remove image:
docker image rm [image_id / image_name]:[tag]
docker rmi [name/image_id]:[tag]
docker rmi [name/image_id]:[tag] -f

To see the progress status of all Docker images:
docker ps -a

To run the docker compose file:
docker compose -f docker_compose.yaml up -d

To stop and remove docker compose file:
docker compose -f docker_compose.yaml down

To remove all images without at least one container associated to them:
docker image prune -a

To remove all stopped containers:
docker container prune

To remove all unused containers, networks, images (both dangling and unused), and optionally, volumes.:
docker system prune