Skip to content

Instantly share code, notes, and snippets.

@bholagabbar
Created September 9, 2023 15:25
Show Gist options
  • Save bholagabbar/6815d958e95580ea2505b13453fa39a4 to your computer and use it in GitHub Desktop.
Save bholagabbar/6815d958e95580ea2505b13453fa39a4 to your computer and use it in GitHub Desktop.
Install Docker and docker-compose on Ubuntu 22.04

Install Docker on Ubuntu 22.04:

  1. Update Software Repositories

    sudo apt update
  2. Install dependencies required to set up Docker's repository:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
  3. Add Docker’s official GPG key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Set up the Docker stable repository:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. Update the repositories again:

    sudo apt update
  6. Install Docker:

    sudo apt install docker-ce
  7. Start Docker and enable it to start at boot:

    sudo systemctl start docker
    sudo systemctl enable docker
  8. To check the Docker version:

    docker --version

Install Docker Compose on Ubuntu 22.04:

  1. Download Docker Compose from the official GitHub repository:

    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

    Note: The version 1.29.2 is mentioned here, but you might want to check the latest version on the Docker Compose release page and replace it in the URL accordingly.

  2. Apply executable permissions to the Docker Compose binary:

    sudo chmod +x /usr/local/bin/docker-compose
  3. To verify the installation:

    docker-compose --version

To run Docker commands without sudo, add the current user to the docker group. Follow these steps to do so:

  1. Add your user to the docker group:

    sudo usermod -aG docker $USER
  2. Activate the changes: You need to log out and log back in to make these group membership changes effective. Alternatively, you can also use the following command to activate the membership without logging out:

    newgrp docker
  3. Verify that you can run Docker without sudo:

    docker run hello-world

    This command should download and run the hello-world Docker container without needing sudo.

For docker-compose, once you can run Docker without sudo, you can also run docker-compose without sudo since it utilizes Docker in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment