Docker is a platform and tool designed to make it easier to create, deploy, and run applications using containers. Containers are lightweight, portable, and self-sufficient units that package an application and its dependencies, along with the necessary runtime, libraries, and system tools. This enables consistent deployment across different environments, from development to production, without worrying about the underlying infrastructure.
Docker provides a way to package and isolate applications within containers, allowing them to run consistently on any system that supports Docker, regardless of differences in operating systems, configurations, or other dependencies.
Key concepts and components of Docker include:
-
Docker Image: A Docker image is a read-only template that contains a set of instructions for creating a runnable instance of an application. Images can be built from a
Dockerfile
, which defines the application and its dependencies. -
Docker Container: A Docker container is a runnable instance of a Docker image. Containers are isolated from each other and from the host system, making them a lightweight and efficient way to package and run applications.
-
Docker Hub: Docker Hub is a cloud-based registry that allows users to store and share Docker images. It hosts a vast collection of pre-built Docker images that can be pulled and used in your applications.
-
Docker Compose: Docker Compose is a tool for defining and running multi-container applications. It uses a YAML file to define the services, networks, and volumes that make up a complex application.
-
Docker Swarm and Kubernetes: Docker Swarm and Kubernetes are orchestration tools that manage the deployment, scaling, and management of containers in a cluster of machines. They provide features for high availability, load balancing, and rolling updates.
-
Dockerfile: A Dockerfile is a script that defines the steps to build a Docker image. It specifies the base image, adds application code, sets environment variables, and performs other necessary setup tasks.
Docker has revolutionized software development and deployment by offering a standardized way to package applications and their dependencies, leading to improved consistency, reproducibility, and efficiency across the software development lifecycle. It has become an essential tool in modern DevOps practices and microservices architectures.
To build a docker image, a Dockerfile is needed, a docker file would look like
FROM rust:1.62.0 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
RUN rm ./target/release/deps/nitride/*
FROM debian:buster-slim as runner
WORKDIR /app
COPY --from=builder /app/target/release/nitride /app/nitride
COPY --from=builder /app/*.toml /app/
EXPOSE 8080
CMD ["/app/nitride"]
A docker image has its own file system, which may be explored using
docker run -it <image_name> sh
Docker does not allow connection to resources on localhost while buildng the images, to change this, user host.docker.internal
in place of localhost
, on Windows and MacOS, on Linux, add --network "host"
when building the imaged
For example,
docker build . -t opeolluwa/nitride --network "host"
docker history --human --format "{{.CreatedBy}}: {{.Size}}" <image_name>
See Reduce the size of your Node.js docker image by up to 90% this also applies ti images built with other technologies such as Rust