Docker & Docker Compose on VPS
by matsjfunke
Option 1: Using apt-get
- Pros: Simple and quick installation with stable, well-tested versions.
- Cons: May not include the latest features and updates.
Step 1: Update and Upgrade Your System
bash
1sudo apt update
2sudo apt upgrade -y
3sudo reboot
4
Step 2: Install Docker and Docker Compose
bash
1sudo apt-get install -y docker.io docker-compose
2
Note: With the 'apt-get method', you might not get the latest features and fixes. Always check the versions installed and update if necessary.
Option 2: Using the Docker Repository
- Pros: Provides access to the latest Docker features and updates with more version control.
- Cons: Involves more complex steps and may introduce newer, less tested features.
Step 1: Update and Upgrade Your System
bash
1sudo apt update
2sudo apt upgrade -y
3sudo reboot
4
Step 2: Install packages to allow apt to use repositories over HTTPS:
bash
1sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
2
Step 3: Add Docker’s Official GPG Key
bash
1curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
2
Step 4: Add the Docker repository to apt sources and update them:
bash
1echo "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
2sudo apt update
3
Step 5: Install Docker
bash
1sudo apt install docker-ce -y
2
3# verify that Docker is installed and running correctly by running a test image:
4sudo docker run hello-world
5
Step 6: Install Docker Compose
bash
1sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2sudo chmod +x /usr/local/bin/docker-compose
3
4# verify with
5docker-compose --version
6
Step 7: Manage Docker as a Non-root User
To avoid using sudo with Docker commands, create a Docker group and add your user:
bash
1sudo usermod -aG docker ${USER}
2
Log out and back in so that your group membership is re-evaluated.