Oracle Cloud Linux에 docker, docker-compose 설치하기

Oracle Cloud에 docker, docker-compose 설치하기

wordpress를 설치하는 방법은 여러가지가 있지만, 내가 직접 운영하는 서버에 설치하는 방법 중에서는 docker를 사용하는 방법이 그나마 간편하고, 추후 재설치시에도 유지보수 비용이 적게드는 방법이라 할 수 있습니다.

추후 설치의 재사용성을 위해, docker compose를 사용하고자 합니다.

본 글에서는, docker 기반 wordpress 설치의 사전 작업에 해당하는 docker, docker-compose 설치 과정을 다루고자 합니다.

docker-compose 설치하기

$ docker-compose

를 실행해 봅시다.

Oracle VM에서는 기본적으로 설치가 안되어 있을 것입니다.

 $ curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
Warning: Failed to create the file /usr/local/bin/docker-compose: Permission
Warning: denied
  0 25.2M    0  1369    0     0   2055      0  3:35:07 --:--:--  3:35:07  2055

권한 에러가 발생했습니다.

$ sudo -I
$ curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
$ exit

docker-compose를 설치합니다.

이제 다시 docker-compose를 실행해 봅시다.

$ docker-compose --version

정상적으로 실행되는 것을 확인할 수 있습니다.

docker engine 설치하기

docker-compose를 설치했지만, docker engine도 사용할 수 있어야 합니다.

$ docker

이 명령어가 실행이 안된다면, 설치를 해줘야 한다는 뜻입니다.
docker-compose도 방금 설치한 분들이라면, docker도 설치가 안되어 있을 가능성이 높습니다.

$ sudo -i

로 root 계정으로 진입합니다.

$ yum install -y yum-utils
$ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum-utils을 설치하고, docker-ce가 있는 repo를 추가해 줍니다.

기본적으로 docker-ce를 위한 repo가 등록되어 있지 않기 때문에, 위의 명령어를 실행해야 향후 docker-ce를 설치하는 명령어를 실행했을 때, 파일을 다운로드할 수 있게 됩니다.

docker-ce.repo를 추가하기 전에는 /etc/yum.repos.d 디렉토리에 보이지 않던 docker-ce.repo 파일이 생깁니다.

$ yum install docker-ce docker-ce-cli containerd.io

이제 docker-ce를 설치합니다.

$ systemctl start docker

docker가 정상적으로 설치되었으면, docker daemon을 띄웁니다.

$ docker run hello-world

이제 docker를 실행시켜 봅니다. hello-world 이미지를 실행시키면 아래와 같이 뜹니다.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe
Status: Downloaded newer image for hello-world:latest

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 ps도 실행해 봅니다.

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

opc 계정에서 docker 명령어 정상 실행 확인

위에서는 root 권한에서 실행하고, 테스트해본 것입니다.

이제 원래의 opc 계정에서도 정상 동작이 되는 것을 확인해 봐야겠죠?

앞서 테스트에서 root 계정에 로그인되어 있다면, exit 명령을 실행하여 opc 계정으로 돌아옵니다.

$ docker
$ docker ps

제 경우는, docker 명령어는 실행이 잘 되지만, docker ps의 명령어는 다음과 같은 에러가 발생했습니다.

$ docker ps
Got 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/containers/json": dial unix /var/run/docker.sock: connect: permission denied

앞서 root 계정으로는 잘 실행되는 것을 확인했는데, 권한이 없어서 안된다고 합니다.

앞으로, root 권한으로 애플리케이션을 실행하는 것은 권장되지 않고, opc와 같은 계정으로 실행해야 하므로 권한 문제를 풀어줍니다.

$ sudo usermod -aG docker $USER

이제 시스템을 재부팅하거나, 나갔다 들어와도 opc 계정에 권한이 부여되어 있음을 확인할 수 있습니다.

$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

앞서 root 계정에서 실행했을 때와 동일한 결과가 출력됩니다.

이제 docker와 docker-compose를 사용할 준비를 마쳤습니다.


2 thoughts on “Oracle Cloud Linux에 docker, docker-compose 설치하기”

Leave a Reply