Logo

Personal Ops Runbook

Personal runbook covering infrastructure operations for Cloud, Kubernetes, OpenStack, and Ceph environments. Includes deployment and teardown procedures, node management, cluster monitoring setup, and incident response workflows compiled from day-to-day operational work. Intended strictly for personal reference — configurations and scripts are environment-specific and not guaranteed to work as-is elsewhere.

Bash script tự động cài đặt Docker và Docker Compose cho hệ điều hành Ubuntu


Mở đầu.

Dưới đây là một fie lệnh Bash script giúp tự động cài đặt Docker và Docker Compose trên hệ điều hành Ubuntu. Hãy sao chép nội dung script này vào một file với đuôi “.sh” (ví dụ: auto.sh) và chạy script để cài đặt Docker và Docker Compose một cách nhanh chóng và dễ dàng.

Nội dung Script.

#!/bin/bash
docker_install(){
    sudo apt-get update -y
    sudo apt-get install ca-certificates curl gnupg lsb-release -y
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    echo "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

    sudo apt-get update -y
    sudo apt-get install docker-ce docker-ce-cli containerd.io -y
    chmod 666 /var/run/docker.sock
    systemctl restart docker && systemctl enable docker
}

docker_compose_install(){
    curl -L "https://github.com/docker/compose/releases/download/v2.6.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    docker-compose -v
}

docker_install
docker_compose_install

Kết Luận

Với script này, bạn có thể tự động cài đặt Docker và Docker Compose trên hệ điều hành Ubuntu một cách dễ dàng. Sau khi chạy script, bạn sẽ có môi trường Docker hoàn chỉnh để tiếp tục khám phá và làm việc với Docker.