githubEdit

Installing Docker and Docker Compose on an Ubuntu server:

Installing Docker and Docker Compose on an Ubuntu server:

Installing Docker on Ubuntu:

  1. Update Package Index:

    sudo apt update
  2. Install Dependencies: Install the packages necessary to allow apt to use a repository over HTTPS:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
  3. Add Docker's Official GPG Key: Add Docker’s official GPG key to your system:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Set Up the Stable Repository: Add the Docker repository to APT sources:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  5. Update the Package Database: Update the package database with Docker packages from the newly added repo:

    sudo apt update
  6. Install Docker CE: Install Docker Community Edition (CE):

    sudo apt install docker-ce
  7. Verify Docker Installation: Check that Docker is installed correctly by running the hello-world image:

    sudo docker run hello-world

Installing Docker Compose:

  1. Download Docker Compose Binary:

    sudo curl -L "https://github.com/docker/compose/releases/download/VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. Apply Executable Permissions:

    sudo chmod +x /usr/local/bin/docker-compose
  3. Create Symbolic Link:

    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  4. Verify Docker Compose Installation:

    docker-compose --version

Post-Installation Steps:

  1. Manage Docker as a Non-root User (Optional):

    • If you want to run Docker commands without sudo, add your user to the docker group:

    • Log out and log back in to apply the group membership changes.

  2. Restart Docker Service:

  3. Test Docker Compose:

    • Create a docker-compose.yml file in your project directory.

    • Define services and configurations in the docker-compose.yml.

    • Run docker-compose up to start the services defined in the YAML file.

Automation Script:

Save the script to a file, for example, install_docker.sh, then make it executable:

To execute the script, run:

Conclusion:

You have now successfully installed Docker and Docker Compose on your Ubuntu server. This setup enables you to manage and deploy containerized applications efficiently.

Last updated