Published on

Modern ways of deployment with Docker

Authors

Deploying Applications with Docker

Docker has revolutionized the way developers build, ship, and run applications. By packaging software into containers, Docker enables consistent environments across development, testing, and production. This article explores 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 shouls show some output, with no list of processes running. So, now it's installed successfully. Congrats!

Docker Context

Well, by default you will be using your machine's docker. Let's call it host. So, if you wish to work with multiple machines - like you want to run command on mulstiple machines, you can set which host you are working with like this:

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

But, there is a better way to do this. You can use docker context. So, you can create multiple contexts and switch between them easily. Here is how you can do it:

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