Linux Server Initial Setup
Linux Server Initial Setup
Section titled “Linux Server Initial Setup”Installing Docker and Setting Up the System
Section titled “Installing Docker and Setting Up the System”This guide introduces setting up a server with Docker and organizing sections to help users get started with development environments.
Sections
Section titled “Sections”-
From Source on a Computer: Direct installation on a local system.
-
Within a Dockerfile: Create a base Dockerfile for repeatable setups.
-
Remotely with Ansible: Automate Docker setup across multiple servers.
-
Without Docker: General system preparation without Docker.
From Source on a Computer
Section titled “From Source on a Computer”Source: Docker Official Documentation
1. Step 1: Install sudo and update the systemapt install -y sudosudo apt updatesudo apt upgrade -y
1. Step 2: Enable unattended-upgradessudo apt install -y unattended-upgradessudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades'
1. Step 3: Install basic toolssudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufwsudo install -m 0755 -d /etc/apt/keyrings
1. Step 4: Set up Dockersudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.ascsudo chmod a+r /etc/apt/keyrings/docker.asc
1. Add the Docker repository to Apt sourcesecho "deb [--print-architecture) signed-by=/etc/apt/keyrings/docker.asc](arch=$(dpkg) https://download.docker.com/linux/debian \$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1. Step 5: Install Dockersudo apt updatesudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
1. Step 6: Add current user to the Docker groupsudo usermod -aG docker $USERRemotely Setting Up with Ansible
Section titled “Remotely Setting Up with Ansible”Automate Docker setup on remote servers using this Ansible playbook:
***- name: Install Docker on remote servers hosts: all become: yes
tasks: - name: Update and upgrade the system apt: update_cache: yes upgrade: dist
- name: Install essential packages apt: name: - sudo - git - ca-certificates - curl - rsync - p7zip-full - unzip state: present
- name: Add Docker GPG key command: > curl -fsSL https://download.docker.com/linux/debian/gpg -o /usr/share/keyrings/docker.gpg
- name: Add Docker repository lineinfile: path: /etc/apt/sources.list.d/docker.list line: > deb [ansible_architecture }} signed-by=/usr/share/keyrings/docker.gpg](arch={{) https://download.docker.com/linux/debian stable
- name: Install Docker apt: name: - docker-ce - docker-ce-cli - containerd.io state: present
- name: Add user to Docker group user: name: "" groups: docker append: yesWithout Docker
Section titled “Without Docker”If Docker is not needed, follow these steps for a basic system setup:
1. Step 1: Install sudo and update the systemapt install -y sudosudo apt updatesudo apt upgrade -y
1. Step 2: Install basic toolssudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufw
1. Step 3: Enable unattended-upgradessudo apt install -y unattended-upgradessudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades'
1. Step 4: Reload necessary servicessystemctl reload postfix