Linux Server Initial Setup: Difference between revisions
Initial |
formatting |
||
Line 1: | Line 1: | ||
= 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 == | ||
* '''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 == | |||
Source: [https://docs.docker.com/engine/install/debian/#install-using-the-repository Docker Official Documentation] | |||
<pre> | |||
# Step 1: Install sudo and update the system | |||
apt install -y sudo | |||
sudo apt update | sudo apt update | ||
sudo apt upgrade -y | sudo apt upgrade -y | ||
# Step 2: Enable unattended-upgrades | |||
sudo apt install -y unattended-upgrades | sudo apt install -y unattended-upgrades | ||
sudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades' | sudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades' | ||
# Step 3: Install basic tools | |||
sudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufw | sudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufw | ||
sudo install -m 0755 -d /etc/apt/keyrings | sudo install -m 0755 -d /etc/apt/keyrings | ||
# Step 4: Set up Docker | |||
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc | sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc | ||
sudo chmod a+r /etc/apt/keyrings/docker.asc | sudo chmod a+r /etc/apt/keyrings/docker.asc | ||
# Add the Docker repository to Apt sources | |||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ | |||
echo | $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | ||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ | |||
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | | |||
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |||
# Step 5: Install Docker | |||
sudo apt update | sudo apt update | ||
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | ||
# Step 6: Add current user to the Docker group | |||
sudo usermod -aG docker $USER | sudo usermod -aG docker $USER | ||
</ | </pre> | ||
< | |||
== Remotely Setting Up with Ansible == | |||
Automate Docker setup on remote servers using this Ansible playbook: | |||
<pre> | |||
--- | |||
- 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 [arch={{ ansible_architecture }} signed-by=/usr/share/keyrings/docker.gpg] | |||
https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable | |||
- name: Install Docker | |||
apt: | |||
name: | |||
- docker-ce | |||
- docker-ce-cli | |||
- containerd.io | |||
state: present | |||
- name: Add user to Docker group | |||
user: | |||
name: "{{ ansible_user }}" | |||
groups: docker | |||
append: yes | |||
</pre> | |||
== Without Docker == | == Without Docker == | ||
If Docker is not needed, follow these steps for a basic system setup: | |||
< | <pre> | ||
# Step 1: Install sudo and update the system | |||
apt install -y sudo | |||
sudo apt update | sudo apt update | ||
sudo apt upgrade -y | sudo apt upgrade -y | ||
# Step 2: Install basic tools | |||
sudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufw | sudo apt install -y git ca-certificates curl rsync pass p7zip-full unzip fail2ban ufw | ||
# Step 3: Enable unattended-upgrades | |||
sudo apt install -y unattended-upgrades | sudo apt install -y unattended-upgrades | ||
sudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades' | sudo sh -c 'echo "APT::Periodic::Update-Package-Lists \"1\"; APT::Periodic::Unattended-Upgrade \"1\";" > /etc/apt/apt.conf.d/20auto-upgrades' | ||
systemctl reload postfix</ | |||
# Step 4: Reload necessary services | |||
systemctl reload postfix | |||
</pre> | |||
== Categories == | |||
[[Category:Docker]] | |||
[[Category:Server Setup]] | |||
[[Category:Self-Hosting]] | |||
[[Category:Guides]] | |||
[[Category:Ansible]] | |||
[[Category:Linux]] | |||
[[Category:Development]] |