사용자 도구

사이트 도구


docker:install_ubuntu

문서의 이전 판입니다!


Docker Install on Ubuntu Linux

Install/설치

Docker Ubuntu Repository를 운영중이다. 저장소를 등록하고 설치한다. ubuntu 버전별 주의점도 읽어봐야 한다.

# docker 에서 제공해주는 리포지토리 설정할 경우curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository -y --no-update "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# docker 제공 저장소 설정을 마친뒤에
sudo apt-get install docker-ce
 
# 만약, Ubuntu 기본 제공 docker를 사용하고자 한다면
sudo apt-get install docker

docker group 추가를 통해 sudo 없이 이용

매번 sudo 명령을 사용하는게 싫을 경우 docker Group에 사용자를 등록해준다. 단, 이 경우 docker 그룹에 속하는 사용자는 root와 맞먹는 권한을 갖기 때문에 보안에 주의해야한다.

# sudo groupadd docker # 보통 미리 추가됨
sudo usermod -aG docker $USER
sudo service docker restart
# logout/login
#  newgrp docker 로그아웃 없이 group 적용됨.
 
# 잘 되는지 확인 sudo 없이
docker run hello-world
 
# ctop 모니터링용
sudo apt-get install ctop

만약 Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?와 같은 메시지가 나오면서 실행이 안된다면 재시작/재로그인을 안 한 때문이거나 DOCKER_HOST 환경변수를 잘못 설정했기 때문이다. 재부팅 하고 DOCKER_HOST 환경변수를 삭제해준다.

부팅시 자동 실행

# systemd
sudo systemctl enable docker

Uninstall

sudo apt-get purge docker-ce
rm -rf /var/lib/docker

Memory와 Swap Accounting 조정

아래와 같은 경고를 만난다면, Memory 옵션과 Swap Accounting Kernel 옵션을 설정하자. docker를 안 사용하더라도 성능상 좋다고 한다.

WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.

/etc/default/grub 파일을 열어서

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
sudo update-grub
# 이후 재부팅한다.

UFW Forwarding 조정

Ubuntu Linux Firewall 사용시 Forwarding 기능을 활성화해야한다. TBD

Docker용 DNS 설정

TBD

Docker Data Storage 변경

  • 기본 저장소는 /var/lib/docker
  • 다른 EXT4 파티션에 docker 이미지와 컨테이너를 저장하고자 한다면(NTFS 파티션에 두지말 것 - 올바로 작동 안 함),
  • 해당 위치에 링크를 걸고, Ubuntu 의 경우 /etc/default/docker 파일에서 옵션을 지정한다. Best way to move docker directory · Issue #3127 · docker/docker
sudo rm /var/lib/docker
sudo ln -s /path/to/docker-storage /var/lib/docker
 
# /etc/default/docker - /var/lib/docker 링크가 가리키는 실제 디렉토리를 지정해 줌
DOCKER_OPTS="-g $(readlink -f /var/lib/docker)"

Docker 자동 시작

  • 14.10 이하는 upstartd를 사용하며, 설치 과정에서 자동시작으로 등록된다.
  • 15.04 이상은 systemd를 사용하며, 아래 명령으로 자동시작 등록한다.
    sudo systemctl enable docker

hello-world 삭제

설치 테스트가 끝났으니 삭제한다.

docker rm `sudo docker ps -aq` # 컨테이너 삭제
docker rmi hello-world # 이미지 삭제

참조

docker/install_ubuntu.1635170751.txt.gz · 마지막으로 수정됨: 2021/10/25 23:05 저자 kwon37xi