Published on

Modern ways of deployment with Docker

Authors

Deploying Applications with Docker

Docker changed how developers build, ship, and run applications. By packaging software into containers, Docker keeps environments consistent across development, testing, and production. This article covers the basics of deploying applications using Docker.

What is Docker?

Docker is an open-source platform that automates the deployment of applications inside lightweight, portable containers. Containers encapsulate an application and its dependencies, ensuring that it runs reliably regardless of the underlying infrastructure.

Why Use Docker for Deployment?

  • Consistency: Containers ensure that your application runs the same way everywhere.
  • Isolation: Each container runs independently, minimizing conflicts between applications.
  • Scalability: Docker makes it easy to scale applications horizontally by running multiple containers.
  • Portability: Containers can be deployed on any system that supports Docker, including cloud providers and on-premises servers.

Installing Docker

Make sure you uninstall the Docker and related files before you begin installation. One click uninstall like this:

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

And there are volumes and other stuff to cleanly uninstall, make sure you follow official documentations to uninstall.

1. Set up Docker's apt repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

2. Install Docker Engine's latest version

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

3. Quick check if the installation was successful

docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

It should show an empty table, with no containers running. That means it installed correctly.

Docker Context

By default you use your machine's Docker. Call it the host. To run commands on multiple machines, you can point at a different host like this:

export DOCKER_HOST=ssh://user@remote-host

A cleaner way is docker context. You can create multiple contexts and switch between them:

docker context create my-remote-site --docker "host=ssh://user@remote-host"

Then you can switch between contexts like this:

docker context use my-remote-site

References

Related Posts