Skip to content

Instantly share code, notes, and snippets.

@opeolluwa
Last active August 11, 2023 05:56
Show Gist options
  • Save opeolluwa/00a0bb8ead840e9199d6fa80fedc139d to your computer and use it in GitHub Desktop.
Save opeolluwa/00a0bb8ead840e9199d6fa80fedc139d to your computer and use it in GitHub Desktop.
Using Docker

Using Docker

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

Docker Image

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"]

Exploring content of a docker image

A docker image has its own file system, which may be explored using

docker run -it <image_name> sh

Allowing network access in building the images

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"

List the contenet of an image and the file sizes

docker history --human --format "{{.CreatedBy}}: {{.Size}}" <image_name>

Reduce image size

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment