IT-INFO

Where IT meets innovation, IT-INFO lights the path to technological brilliance

Getting Started with Docker and Docker Compose

Getting Started with Docker and Docker Compose

This guide will walk you through the installation of Docker and Docker Compose, and how to run your first containerized application.

Installation

Docker

First, let's install Docker. The following commands will work for a variety of Linux distributions. If you're using Windows or macOS, please refer to the official Docker documentation.

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker

Docker Compose

Next, install Docker Compose by running the following commands:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Running Your First Container

With Docker installed, you can now run your first container. We'll use the hello-world image to verify that everything is working correctly.

sudo docker run hello-world

Using Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. Let's create a simple web application using Docker Compose.

Step 1: Define the application dependencies

Create a directory for your project and navigate into it:

mkdir my-web-app
cd my-web-app

In this directory, create a file named docker-compose.yml with the following content:

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"

Step 2: Run the application

Now, run the application using Docker Compose:

sudo docker-compose up

Your web application is now running and accessible at http://localhost.

Conclusion

In this guide, you've learned how to install Docker and Docker Compose, and how to run your first containerized application. Docker and Docker Compose are powerful tools that simplify the process of deploying and managing applications in containers.

Created on Aug. 7, 2024, 12:04 p.m.