Skip to content
KYND Dev

Technical Notes: Setting Up an Ubuntu Server for Docker Compose

AI, MLOps, Linux1 min read

In this technical notes, I'll walk through the process of setting up an Ubuntu server to host Docker Compose services. This setup includes installing Docker, configuring the NVIDIA Container Toolkit (if required for GPU-based workloads), and running a sample service with Docker Compose.


Prerequisites

Before start, ensure you have the following:

  • A fresh Ubuntu server with SSH access.
  • Administrative (root) privileges on the server.

Step 1: Update and Upgrade the System

First, connect to your server via SSH and update the package list. It's always a good practice to ensure your system is up-to-date.

1sudo apt update
2sudo apt upgrade -y

Step 2: Install Docker

Docker is a platform that allows you to build, ship, and run applications in lightweight containers. To install Docker, use the official installation script:

1curl -fsSL https://get.docker.com -o get-docker.sh
2sudo sh get-docker.sh

After installation, add your user to the docker group so you can run Docker commands without sudo:

1sudo usermod -aG docker $USER

Apply the group changes by logging out and logging back in, or use:

1su - $USER

Verify the Docker installation:

1docker --version

Step 3: Install NVIDIA Container Toolkit (Optional for GPU Workloads)

If your service requires GPU acceleration, install the NVIDIA Container Toolkit.

  1. Configure the repository:
1curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
2 && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
3 sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
4 sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
  1. Update the package list and install the toolkit:
1sudo apt-get update
2sudo apt-get install -y nvidia-container-toolkit
  1. Install nvidia-docker2:
1sudo apt-get install -y nvidia-docker2
  1. Restart the Docker service:
1sudo systemctl restart docker

Step 4: Install Docker Compose

Docker Compose simplifies the process of defining and running multi-container Docker applications. Install it as follows:

1sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Make the binary executable:

1sudo chmod +x /usr/local/bin/docker-compose

Verify the installation:

1docker-compose --version

Step 5: Build Docker Images

Navigate to the directory containing your docker-compose.yml file. This file defines the services for your application. Build the Docker images:

1cd /path/to/your/project
2docker-compose build

Step 6: Run Your Docker Containers

Start your service with Docker Compose:

1docker-compose up -d

Check the running containers:

1docker-compose ps

Conclusion

We now have a fully functional Ubuntu server configured to run Docker Compose services. With this setup, you can deploy microservices, web applications, and other containerized workloads efficiently. If our application requires GPU acceleration, the NVIDIA Container Toolkit ensures seamless integration.