728x90
<Docker 설치 명령어>
- Virtual Box / Ubuntu에서 Docker 설치
- 이전 버전 설치 제거
sudo apt-get remove docker docker-engine docker.io containerd runc
- 패키지 설치 툴 명령어
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
<이미지 관련 명령어>
- 이미지 목록 확인
ubuntu@ubuntu-VirtualBox:~$ docker image ls
ubuntu@ubuntu-VirtualBox:~$ docker images -a (모든 이미지 표시)
- 이미지 상세 정보 표시
ubuntu@ubuntu-VirtualBox:~$ docker image inspect boot:letest
- 이미지 제작 히스토리 확인
ubuntu@host1:~$ docker image history noderun:1.0
IMAGE CREATED CREATED BY SIZE COMMENT
d77d5ca0759f 2 days ago CMD ["node" "runapp.js"] 0B buildkit.dockerfile.v0
<missing> 2 days ago ENTRYPOINT ["/sbin/tini" "--"] 0B buildkit.dockerfile.v0
<missing> 2 days ago EXPOSE map[6060/tcp:{}] 0B buildkit.dockerfile.v0
<missing> 2 days ago COPY runapp.js . # buildkit 317B buildkit.dockerfile.v0
<missing> 2 days ago WORKDIR /app 0B buildkit.dockerfile.v0
<missing> 2 days ago RUN /bin/sh -c apk add --no-cache tini curl … 2.36MB buildkit.dockerfile.v0
<missing> 6 weeks ago /bin/sh -c #(nop) CMD ["node"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry… 0B
<missing> 6 weeks ago /bin/sh -c #(nop) COPY file:4d192565a7220e13… 388B
<missing> 6 weeks ago /bin/sh -c apk add --no-cache --virtual .bui… 7.76MB
<missing> 6 weeks ago /bin/sh -c #(nop) ENV YARN_VERSION=1.22.19 0B
<missing> 6 weeks ago /bin/sh -c addgroup -g 1000 node && addu… 121MB
<missing> 6 weeks ago /bin/sh -c #(nop) ENV NODE_VERSION=20.10.0 0B
<missing> 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ADD file:80331a5d882ac8a70… 7.06MB
- 이미지 생성 (이미지 수정해서 다시 올려야 할 때도 사용)
ubuntu@ubuntu-VirtualBox:~$ docker build -t [dockerHub ID]/[이미지명]:[태그명] [DockerFile위치] .
** 맨 뒤에 .을 붙여줘야 함
- 이미지 삭제
ubuntu@ubuntu-VirtualBox:~$ docker rmi [이미지 ID]
ubuntu@ubuntu-VirtualBox:~$ docker image rm [옵션] 이미지명 [이미지명]
- 컨테이너 + 이미지 강제 삭제
ubuntu@ubuntu-VirtualBox:~$ docker rmi -f [이미지 ID]
- 이미지 다운로드
ubuntu@ubuntu-VirtualBox:~$ docker image pull [옵션] 이미지명[:태그명]
- 이미지 태그 지정 (이미지에 별명 지정)
ubuntu@ubuntu-VirtualBox:~$ docker tag <소스 이미지> <docker hub 사용자명>/이미지명:[태그명]
- 이미지 업로드
ubuntu@ubuntu-VirtualBox:~$ docker image push <Docker Hub 사용자>/이미지명[:태그명]
- 서버 간 이미지 파일 전달
** 도커 이미지를 압축해 저장
ubuntu@ubuntu-VirtualBox:~$ docker image save (아이디)/myweb:1.0 | gzip > myweb1.0.tar.gz
** 도커 이미지 전송
ubuntu@ubuntu-VirtualBox:~$ scp ./myweb1.0.tar (전달할서버이용자)@(전달IP):/(파일경로)
** 이미지 등록
ubuntu@ubuntu-VirtualBox:~$ docker image load < myweb1.0.tar
<컨테이너 관련 명령어>
- 컨테이너 시작 및 중지
** 컨테이너 시작
ubuntu@ubuntu-VirtualBox:~$ docker start [컨테이너명, ID]
** 컨테이너 중지
ubuntu@ubuntu-VirtualBox:~$ docker stop [컨테이너명, ID]
- 실행 중인 컨테이너 확인
ubuntu@ubuntu-VirtualBox:~$ docker ps
- 컨테이너 삭제
ubuntu@ubuntu-VirtualBox:~$ docker rm [컨테이너 ID]
- 컨테이너 전체 삭제
ubuntu@ubuntu-VirtualBox:~$ docker rm 'docker ps -a -q'
- 컨테이너 생성 및 실행
ubuntu@ubuntu-VirtualBox:~$ docker run [options] image[:tag, @digest] [command] [args]
<옵션>
- -it: 컨테이너에 대화형으로 접근할 수 있고, 컨테이너 내부에서 명령어를 실행하고 결과를 확인 (-it 뒤에 /bin/bash 적기)
- -d: 컨테이너가 백그라운드에서 동작
- -name: 컨테이너에 이름 부여
- -env(-e): 컨테이너 내에서 사용할 시스템 환경 변수를 지정
- -v: 호스트 경로와 컨테이너 경로의 공유 볼륨 설정
- -p [Host 포트]:[Container port]: 호스트의 특정 포트와 컨테이너의 특정 포트를 매핑할 때 사용
- -link=[container:container_id]: 두 개 이상의 컨테이너를 연결
- 컨테이너 생성 (시작은 되지 않고 생성만 되기 때문에 실행하려면 exec 명령어 사용
ubuntu@ubuntu-VirtualBox:~$ docker container create [컨테이너명, ID]
- 실행 중인 컨테이너에 접속 (exit로 종료)
ubuntu@ubuntu-VirtualBox:~$ docker exec -it [컨테이너명, ID] /bin/bash
- 서버 간 컨테이너 전송
ubuntu@ubuntu-VirtualBox:~$ docker container export (컨테이너 이름) > (컨테이너이름).압축확장자(tar)
ubuntu@ubuntu-VirtualBox:~$ scp ./myweb1.0.tar (전달할서버이용자)@(전달IP):/(파일경로)
ubuntu@ubuntu-VirtualBox:~$ docker image import - my_container2:2.0
- 컨테이너 모니터링
ubuntu@ubuntu-VirtualBox:~$ docker container top
ubuntu@ubuntu-VirtualBox:~$ docker container logs
- 컨테이너 포트 확인
ubuntu@ubuntu-VirtualBox:~$ docker container port [컨테이너 이름]
- 컨테이너 가동 상태 확인
ubuntu@ubuntu-VirtualBox:~$ docker container status [컨테이너 이름]
'클라우드 + DevOps > Docker' 카테고리의 다른 글
Docker 실습 :: 윈도우 Window에서 Docker 설치 과정 (0) | 2024.04.06 |
---|---|
Docker와 Kubernetes 소개 이론 정리 (0) | 2024.04.05 |
Docker 실습 :: Dockerfile 제작 후 이미지 생성 (0) | 2024.03.01 |
Docker 마운트 실습 :: 스토리지 드라이버 설정(--storage-opt)과 pquota 마운트 (0) | 2024.02.29 |
Docker 마운트 실습 :: 마운트를 이용한 NginX 로그 기록 관리 (1) | 2024.02.28 |