본문 바로가기

퍼블릭 클라우드

EC2 인스턴스에 Docker를 설치하고 Nginx Docker 컨테이너를 올리는 방법

728x90

EC2 인스턴스에 Docker를 설치하고 Nginx Docker 컨테이너를 올리는 방법

aws ec2 인스턴스에서 도커 설치 및 nginx 컨테이너 올리기

테스트 환경

$ cat /etc/os-release 
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

도커 설치(docker install)

도커 패키지 검색

amazon-linux-extras list
$ amazon-linux-extras list
...
 20  docker=latest            enabled      \
        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
...

도커 설치

amazon-linux-extras install docker

(or)

amazon-linux-extras install docker=stable
$ amazon-linux-extras install docker=stable
Installing:
 docker
Installing for dependencies:
 containerd
 libcgroup
 pigz
 runc

$ docker --version
Docker version 20.10.4, build d3cb89e

도커(docker) 서비스 기동 및 버전 정보

systemctl restart docker
docker version
$ docker version          
Client:
 Version:           20.10.4
 API version:       1.41
 Go version:        go1.15.8
 Git commit:        d3cb89e
 Built:             Mon Mar 29 18:54:36 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.4
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.15.8
  Git commit:       363e9a8
  Built:            Mon Mar 29 18:55:03 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

도커 컴포즈 설치(docker-compose install)

최신 버전 설치 및 권한 변경

curl -fsSL https://github.com/docker/compose/releases/download/$(curl -s https://github.com/docker/compose/releases/latest \
| sed 's#.*tag/\(.*\)\".*#\1#')/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose \
&& ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

최신 버전 확인 https://github.com/docker/compose/releases

curl -fsSL https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
728x90

 

ctop 설치(ctop install)

최신 버전 확인 https://github.com/bcicen/ctop/releases

$ curl -s https://github.com/bcicen/ctop/releases/latest | sed 's#.*tag/\(.*\)\".*#\1#'
v0.7.5
curl -fsSL https://github.com/bcicen/ctop/releases/download/v0.7.5/ctop-0.7.5-linux-amd64 -o /usr/local/bin/ctop
chmod +x /usr/local/bin/ctop
$ ctop -v
ctop version 0.7.5, build c971d26 go1.15.3

jq 패키지 설치

yum install -y jq
$ yum install -y jq
Installing:
 jq
Installing for dependencies:
 oniguruma
$ jq --version
jq-1.5

nginx 컨테이너 올리기

nginx 이미지 검색

docker search nginx
$ docker search nginx
NAME                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                      Official build of Nginx.                        14968     [OK]       
jwilder/nginx-proxy        Automated Nginx reverse proxy for docker con…   2033                 [OK]
richarvey/nginx-php-fpm    Container running Nginx + PHP-FPM capable of…   813                  [OK]

컨테이너 이미지 다운로드 및 컨테이너 올리기(실행)

docker run -d -p 80:80 nginx
$ docker run -d -p 80:80 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
69692152171a: Pull complete 
30afc0b18f67: Pull complete 
596b1d696923: Pull complete 
febe5bd23e98: Pull complete 
8283eee92e2f: Pull complete 
351ad75a6cfa: Pull complete 
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Downloaded newer image for nginx:latest
22b648880d15936c5d9bc77a485e3158a0ac3b3b0f71ccccfe081df0edd8bd8f

nginx 컨테이너 서비스 확인

$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

728x90