728x90

리눅스에서 도커 설치하기

들어가며

  • 리눅스에서 빠르게 도커(Docker)를 설치해보자.
  • 우분투(Ubuntu) 22.04 LTS에서 도커를 설치해본다.

 

방법

도커 설치 환경 구축하기

  • 도커를 설치하기에 앞서, 설치 환경을 구축한다.

 

우분투 리눅스 업데이트(업그레이드) 하기
$ sudo apt-get update
$ sudo apt-get upgrade

 

혹시나 시스템에 설치되어 있는 도커 제거하기
$ sudo apt-get remove docker docker-engine docker.io containerd runc

 

도커를 설치하기 위해 필요한 패키지들을 설치하기

 

$ sudo apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> gnupg \
> lsb-release

 

도커의 공식 GPS 키 추가하기
$ sudo install -m 0755 -d /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ sudo chmod a+r /etc/apt/keyrings/docker.gpg

 

도커 레지스트리(Registry) 구성하기
$ echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

 

도커 설치하기

  • 이제 본격적으로 도커를 우분투에 설치해본다.

 

지금까지 몇 가지 변화가 있었으므로, 업데이트할 것이 있는지 체크하고 업데이트하기
$ sudo apt-get update

 

Docker Engine, containerd, Docker Compose 설치하기
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

 

도커가 성공적으로 설치되었는지 확인해보기
$ docker

 

  • 위의 명령을 실행하여 아래와 같이 출력되면 성공적으로 도커가 설치된 것이다.
Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Log in to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  buildx*     Docker Buildx (Docker Inc., v0.10.4)
  compose*    Docker Compose (Docker Inc., v2.18.1)
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Swarm Commands:
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Global Options:
      --config string      Location of client config files (default "/home/devastra/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket to connect to
  -l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/home/devastra/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/devastra/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/devastra/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Run 'docker COMMAND --help' for more information on a command.

For more help on how to use Docker, head to https://docs.docker.com/go/guides/

 

@sudo@ 명령을 입력하지 않고 도커 명령어를 실행하기

  • 일반 유저도커 명령어를 사용할 때 항상 @sudo@ 명령문을 맨 앞에 적어줘야 한다.
  • 이러한 불편함을 없애도록 일반 유저에게 @sudo@ 권한을 줘보자.

 

일반 유저에게 @sudo@ 권한 주기
$ sudo usermod -a -G docker $USER

 

도커 재시작 하기
$ sudo service docker restart

 

리눅스 접속을 해제하고 다시 접속하기
$ exit
> ssh 관리자ID@가상머신_공용IP주소

 

@hello-world@ 안내문 출력해보기
  • 일반 유저에게 @sudo@ 권한을 주지 않으면, @sudo docker run hello-world@ 명령을 실행해줘야 한다. (번거롭다.)
$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

 

참고 사이트

도커 공식 문서
 

Docker Docs: How to build, share, and run applications

 

docs.docker.com

 

도커 설치 가이드 공식 문서
 

Install Docker Engine on Ubuntu

 

docs.docker.com

 

우분투에 도커 설치하기 (자세히)
 

[Azure] 도커(Docker) 실습하기 : 도커 설치하기

애저(Azure)를 이용하여 도커(Docker) 실습하기 : 도커 설치하기 들어가며 애저(Azure)를 이용하여 도커(Docker)를 설치해보자. 도커(Docker) 리눅스의 응용 프로그램들을 프로세스 격리 기술들을 사용해

dev-astra.tistory.com

 

728x90