클라우드 + DevOps/Docker

가상머신 Virtual Box에서 Docker 접속하기

gamjadori 2024. 2. 2. 10:38
728x90

<Virtual Box에서 Docker 설치>

<설정>

  • 오디오 사용 안 함
  • 하드디스크 2개 생성 (sda, sdb: 물리적인 하드디스크는 sd~로 시작)

<Ubuntu 서버 설치 설정>

1. Ubuntu 설치 중 업데이트 다운로드 체크 해제

2. 설치 형식: 기타

3. 하드디스크에 파티션 설정

sda(OS 설치): 30GB

sdb (APP 설치): 60GB >> 하드디스크 2개 되어있는지 확인

 

  • 파티션 추가

1. sda 파티션 추가

용도: XFS 저널링 파일 시스템
마운트 위치: /

2. sdb 파티션 추가 (2개)

크기: 15000
마운트 위치: /DATA
용도: EXT4 저널링 파일 시스템

 

크기: 남은 크기 모두
용도: XFS 저널링 파일 시스템
마운트 위치: /var/lib/docker

>> 우분투 서버 설치

  • 네트워크 설정
  • 이더넷 (enp0s8) 설정: 192.168.56.101

  • 게이트웨이, 도메인, 구글 ping 확인

도메인

게이트웨이

구글 >> 외부 네트워크가 잡혀야 함 (서비스 다운로드)

 

[틈새] 우분투 명령어 정리

  • ip a: IP 주소 확인
  • sudo apt -y update sudo apt -y install openssh-server vim net-tools

>> ping 192.168.56.101이 되면 vscode 접속 가능

 

<Config 작성 양식>

Host ubuntu@192.168.56.101
  HostName 192.168.56.101
  User ubuntu
  Port 22

<도커 설치>

  • 패키지 설치 툴 명령어
sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  • 공식 GPG 키 등록>
ubuntu@ubuntu-VirtualBox:~$‌ curl -fsSL <https://download.docker.com/linux/ubuntu/gpg> | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • 공식 GPG 키가 추가 확인
ubuntu@ubuntu-VirtualBox:~$‌ sudo apt-key fingerprint 0EBFCD88
  • 도커 저장소 설정
ubuntu@ubuntu-VirtualBox:~$ 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
  • 도커 설치 및 버전 확인
ubuntu@ubuntu-VirtualBox:~$ sudo apt update
ubuntu@ubuntu-VirtualBox:~$ sudo apt -y install docker-ce
ubuntu@ubuntu-VirtualBox:~$ sudo docker version
Client: Docker Engine - Community
Version:           24.0.7
API version:       1.43
Go version:        go1.20.10
Git commit:        afdd53b
Built:             Thu Oct 26 09:07:41 2023
OS/Arch:           linux/amd64
Context:           default

Server: Docker Engine - Community
Engine:
Version:          24.0.7
API version:      1.43 (minimum version 1.12)
Go version:       go1.20.10
Git commit:       311b9ff
Built:            Thu Oct 26 09:07:41 2023
OS/Arch:          linux/amd64
Experimental:     false
containerd:
Version:          1.6.26
GitCommit:        3dd1e886e55dd695541fdcd67420c2888645a495
runc:
Version:          1.1.10
GitCommit:        v1.1.10-0-g18a0cb0
docker-init:
Version:          0.19.0
GitCommit:        de40ad0
  • 도커 사용 권한 부여
ubuntu@ubuntu-VirtualBox:~$ sudo usermod -aG docker ubuntu
  • 사용 권한 적용
ubuntu@ubuntu-VirtualBox:~$ sudo systemctl daemon-reload
ubuntu@ubuntu-VirtualBox:~$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
ubuntu@ubuntu-VirtualBox:~$ sudo systemctl restart docker
  • 도커 버전 확인 >> 끝
ubuntu@ubuntu-VirtualBox:~$ docker version
Client: Docker Engine - Community
Version:           24.0.7
API version:       1.43
Go version:        go1.20.10
Git commit:        afdd53b
Built:             Thu Oct 26 09:07:41 2023
OS/Arch:           linux/amd64
Context:           default
permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
  • 도커 호스트 다시 시작: 우클릭 > 시작 > 헤드리스 시작(백그라운드에서 시작) 아무것도 안 뜨고, 미리보기로 뜨게 함
  • Vscode로 접속
    •