Linux에 Docker 및 Docker Compose 설치

공식 페이지


  • Ubuntu에 Docker 엔진 설치: https://docs.docker.com/engine/install/ubuntu/#installation-methods
  • 대부분의 Linux 배포판에 대한 Docker 설치 스크립트: https://github.com/docker/docker-install
  • 대부분의 Linux 배포판에 대한 NVIDIA Docker 설치 안내서: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit
  • Linux용 설치 후 단계: https://docs.docker.com/engine/install/linux-postinstall
  • Docker Compose 설치: https://docs.docker.com/compose/install/#install-compose
  • Docker Compose github 릴리스: https://github.com/docker/compose/releases
  • Compose V2: https://docs.docker.com/compose/cli-command/#install-on-linux



  • 1. 도커 설치



    1.1. 스크립트로 Docker 설치




    # Download docker installer script:
    curl -fsSL https://get.docker.com -o get-docker.sh
    # Install docker by 'get-docker.sh' script:
    DRY_RUN=1 sudo sh get-docker.sh
    
    # Remove downloaded script:
    rm -vrf get-docker.sh
    
    # To avoid using 'sudo' for docker commands:
    # Create a new 'docker' group:
    sudo groupadd docker
    # Add current user to the 'docker' group:
    sudo usermod -aG docker $(whoami)
    
    # Apply new group changes to the new shell session:
    newgrp docker
    # Or reboot the system to apply docker group changes:
    sudo shutdown -r now
    
    # Configure docker to start on reboot:
    sudo systemctl enable docker.service
    sudo systemctl enable containerd.service
    
    # Check docker is installed and running:
    docker -v
    docker info
    docker images
    


    1.2. [GPU 전용] NVIDIA Docker 설치


  • NVIDIA GPU가 없으면 이 단계를 건너뛰십시오!

  • [필수] NVIDIA GPU 드라이버 설치: https://github.com/bybatkhuu/wiki/blob/main/posts/manuals/installs/nvidia-driver-linux.md
  • Ubuntu/Debian 기반 Linux 배포판의 경우:

  • ## [IMPORTANT] Only for Ubuntu/Debian-based linux
    # Download the nvidia-docker GPG key and setup the stable repository:
    distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
       && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
       && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
    
    # Update repository list:
    sudo apt-get update
    # Install nvidia-docker2:
    sudo apt-get install -y nvidia-docker2
    

    /etc/docker/daemon.json 파일을 편집합니다.

    sudo nano /etc/docker/daemon.json
    

    default-runtime 파일에 다음/etc/docker/daemon.json을 추가합니다.

    {
        "default-runtime": "nvidia"
    }
    


    예를 들어:

    {
        "default-runtime": "nvidia",
        "runtimes":
        {
            "nvidia":
            {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        }
    }
    


    변경 사항을 저장하고 파일 편집기를 종료합니다.

    # Restart docker service:
    sudo systemctl daemon-reload
    sudo systemctl restart docker.service
    


    2. [권장] 도커 로그 파일 최대 크기 및 최대 회전 제한


    /etc/docker/daemon.json 파일을 편집합니다.

    sudo nano /etc/docker/daemon.json
    

    log-opts 파일에 다음/etc/docker/daemon.json을 추가합니다.

    {
        "log-opts":
        {
            "max-size": "10m",
            "max-file": "10"
        }
    }
    


    변경 사항을 저장하고 파일 편집기를 종료합니다.

    # Restart docker service:
    sudo systemctl restart docker.service
    


    3. Docker Compose V2 설치




    ## Download docker-compose binary release:
    # [RECOMMENDED] Compose v2.2.3 (Linux) release:
    sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
    # [For old version] Compose v1.29.2 (Linux) release:
    # 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
    # [Only for experimental] Latest version release:
    # sudo curl -L $(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep linux-$(uname -m)\" | cut -d '"' -f 4) -o /usr/local/bin/docker-compose
    
    # Apply executable permission to the docker-compose binary:
    sudo chmod +x /usr/local/bin/docker-compose
    
    # Create a symbolic link to '/usr/bin':
    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
    
    # Check docker-compose version:
    docker-compose --version
    


    👍 ✨

    설치 완료




    [선택사항] 도커 데이터 디렉토리를 외부 저장소로 변경




    # Stop the docker service:
    sudo systemctl stop docker.service
    

    /etc/docker/daemon.json 파일을 편집합니다.

    sudo nano /etc/docker/daemon.json
    

    data-root 파일에 다음/etc/docker/daemon.json을 추가합니다([NEW_STORAGE_PATH]를 새 디렉토리로 변경하는 것을 잊지 마십시오).

    {
       "data-root": "[NEW_STORAGE_PATH]/docker/data-root"
    }
    


    예를 들어:

    {
       "data-root": "/mnt/ssd/1/docker/data-root"
    }
    


    변경 사항을 저장하고 파일 편집기를 종료합니다.

    # Copy the current docker data directory to the new directory:
    sudo rsync -a /var/lib/docker/ [NEW_STORAGE_PATH]/docker/data-root
    # For example:
    sudo rsync -a /var/lib/docker/ /mnt/ssd/1/docker/data-root
    
    # Rename the old docker data directory as a backup:
    sudo mv /var/lib/docker /var/lib/docker.old
    
    # Start docker service:
    sudo systemctl start docker.service
    
    # Test docker is working properly:
    docker -v
    docker info
    docker images
    docker ps -a
    
    # Remove the old backup docker data directory:
    sudo rm -rf /var/lib/docker.old
    


    [선택사항] docker-compose용 명령 자동 완성 설치




    # Download docker-compose auto-completion script into '/etc/bash_completion.d/':
    sudo curl \
        -L https://raw.githubusercontent.com/docker/compose/1.29.2/contrib/completion/bash/docker-compose \
        -o /etc/bash_completion.d/docker-compose
    
    # Reload current bash shell session:
    source ~/.bashrc
    



    참조


  • Docker 지원 플랫폼(OS): https://docs.docker.com/engine/install
  • NVIDIA GPU 드라이버 설치: https://github.com/bybatkhuu/wiki/blob/main/posts/manuals/installs/nvidia-driver-linux.md
  • Docker 데이터 루트 디렉터리 변경: https://tienbm90.medium.com/how-to-change-docker-root-data-directory-89a39be1a70b
  • 좋은 웹페이지 즐겨찾기