網頁

2023/6/13

AWS EC2 Linux AMI(Amazon Linux 2023) 安裝Docker

在AWS EC2 instance Linux AMI(Amazon Linux 2023) 安裝Docker。


範例環境:

  • macOS Ventura 13.0.1


SSH連線到EC2

在本機(Mac)以SSH連線到EC2 isntance

~$ ssh -i demo-key.pem ec2-user@18.182.60.14
The authenticity of host '18.182.60.14 (18.182.60.14)' can't be established.
ED25519 key fingerprint is SHA256:XfVQ0Uf6oi0vJfOvj6a8aZyD7HZLiXRyE3+zI9y8U2U.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:11: ec2-18-183-21-206.ap-northeast-1.compute.amazonaws.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '18.182.60.14' (ED25519) to the list of known hosts.
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
Last login: Tue Mar 28 04:58:35 2023 from 211.20.37.118


安裝Docker

連線到EC2 instance後,輸入sudo yum update -y更新套件庫。

[ec2-user@ip-172-31-14-20 ~]$ sudo yum update -y
Amazon Linux 2023 repository                                                                                                                                                                                                                     23 kB/s | 3.6 kB     00:00
Amazon Linux 2023 Kernel Livepatch repository                                                                                                                                                                                                    20 kB/s | 2.9 kB     00:00
Amazon Linux 2023 Kernel Livepatch repository
...
Dependencies resolved.
Nothing to do.
Complete!


安裝之前輸入sudo yum info docker查看要安裝的docker版本資訊。

[ec2-user@ip-172-31-14-20 ~]$ sudo yum info docker
Last metadata expiration check: 0:00:26 ago on Tue Jun 13 06:00:07 2023.
Available Packages
Name         : docker
Version      : 20.10.17
Release      : 1.amzn2023.0.5
Architecture : x86_64
Size         : 39 M
Source       : docker-20.10.17-1.amzn2023.0.5.src.rpm
Repository   : amazonlinux
Summary      : Automates deployment of containerized applications
URL          : http://www.docker.com
License      : ASL 2.0 and MIT and BSD and MPLv2.0 and WTFPL
Description  : Docker is an open-source engine that automates the deployment of any
             : application as a lightweight, portable, self-sufficient container that will
             : run virtually anywhere.
             :
             : Docker containers can encapsulate any payload, and will run consistently on
             : and between virtually any server. The same container that a developer builds
             : and tests on a laptop will run at scale, in production*, on VMs, bare-metal
             : servers, OpenStack clusters, public instances, or combinations of the above.

輸入sudo yum install docker安裝Docker。

[ec2-user@ip-172-31-14-20 ~]$ sudo yum install docker
Last metadata expiration check: 0:01:38 ago on Tue Jun 13 06:00:07 2023.
Dependencies resolved.
================================================================================================================================================================================================================================================================================
 Package                                                                 Architecture                                            Version                                                                     Repository                                                    Size
================================================================================================================================================================================================================================================================================
Installing:
 docker                                                                  x86_64                                                  20.10.17-1.amzn2023.0.5                                                     amazonlinux                                                   39 M
Installing dependencies:
 containerd                                                              x86_64                                                  1.6.8-2.amzn2023.0.3                                                        amazonlinux                                                   31 M
 iptables-libs                                                           x86_64                                                  1.8.8-3.amzn2023.0.2                                                        amazonlinux                                                  401 k
 iptables-nft                                                            x86_64                                                  1.8.8-3.amzn2023.0.2                                                        amazonlinux                                                  183 k
 libcgroup                                                               x86_64                                                  3.0-1.amzn2023.0.1                                                          amazonlinux                                                   75 k
 libnetfilter_conntrack                                                  x86_64                                                  1.0.8-2.amzn2023.0.2                                                        amazonlinux                                                   58 k
 libnfnetlink                                                            x86_64                                                  1.0.1-19.amzn2023.0.2                                                       amazonlinux                                                   30 k
 libnftnl                                                                x86_64                                                  1.2.2-2.amzn2023.0.2                                                        amazonlinux                                                   84 k
 pigz                                                                    x86_64                                                  2.5-1.amzn2023.0.3                                                          amazonlinux                                                   83 k
 runc                                                                    x86_64                                                  1.1.3-1.amzn2023.0.2                                                        amazonlinux                                                  3.0 M

Transaction Summary
================================================================================================================================================================================================================================================================================
Install  10 Packages

Total download size: 74 M
Installed size: 286 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): iptables-libs-1.8.8-3.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                           4.5 MB/s | 401 kB     00:00
(2/10): libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                           328 kB/s |  30 kB     00:00
(3/10): libcgroup-3.0-1.amzn2023.0.1.x86_64.rpm                                                                                                                                                                                                 768 kB/s |  75 kB     00:00
(4/10): iptables-nft-1.8.8-3.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                            3.5 MB/s | 183 kB     00:00
(5/10): libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                  1.7 MB/s |  58 kB     00:00
(6/10): runc-1.1.3-1.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                                     21 MB/s | 3.0 MB     00:00
(7/10): pigz-2.5-1.amzn2023.0.3.x86_64.rpm                                                                                                                                                                                                      1.8 MB/s |  83 kB     00:00
(8/10): libnftnl-1.2.2-2.amzn2023.0.2.x86_64.rpm                                                                                                                                                                                                1.9 MB/s |  84 kB     00:00
(9/10): docker-20.10.17-1.amzn2023.0.5.x86_64.rpm                                                                                                                                                                                                43 MB/s |  39 MB     00:00
(10/10): containerd-1.6.8-2.amzn2023.0.3.x86_64.rpm                                                                                                                                                                                              27 MB/s |  31 MB     00:01
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                            53 MB/s |  74 MB     00:01
...                                                                       10/10
Installed:
  containerd-1.6.8-2.amzn2023.0.3.x86_64       docker-20.10.17-1.amzn2023.0.5.x86_64    iptables-libs-1.8.8-3.amzn2023.0.2.x86_64    iptables-nft-1.8.8-3.amzn2023.0.2.x86_64    libcgroup-3.0-1.amzn2023.0.1.x86_64    libnetfilter_conntrack-1.0.8-2.amzn2023.0.2.x86_64
  libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64    libnftnl-1.2.2-2.amzn2023.0.2.x86_64     pigz-2.5-1.amzn2023.0.3.x86_64               runc-1.1.3-1.amzn2023.0.2.x86_64

Complete!

安裝完後輸入docker --version檢視版本。

[ec2-user@ip-172-31-14-20 ~]$ docker --version
Docker version 20.10.17, build 100c701


其他設定

輸入sudo usermod -a -G docker ec2-user把ec2-user使用者加到docker的user group,這樣之後執行docker命令前面就不用加sudo

[ec2-user@ip-172-31-14-20 ~]$ sudo usermod -a -G docker ec2-user

輸入newgrp docker重新載入docker user group設定。

[ec2-user@ip-172-31-14-20 ~]$ newgrp docker


啟動Docker服務

輸入sudo systemctl enable docker讓EC2每次重啟時會自動啟動docker服務。

[ec2-user@ip-172-31-14-20 ~]$ sudo systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

輸入sudo service docker start啟動docker服務。

[ec2-user@ip-172-31-14-20 ~]$ sudo service docker start
Redirecting to /bin/systemctl start docker.service

輸入docker info查看已安裝的docker的詳細資訊)。

[ec2-user@ip-172-31-14-20 ~]$ docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: 1e7bb5b773162b57333d57f612fd72e3f8612d94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 6.1.15-28.43.amzn2023.x86_64
 Operating System: Amazon Linux 2023
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 963.9MiB
 Name: ip-172-31-14-20.ap-northeast-1.compute.internal
 ID: 6FVP:PBNP:GS36:A3LF:VYRL:7G5G:DSFV:7AMP:LY7M:5JAT:MOMJ:XAYD
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

輸入sudo systemctl status docker.service查看docker服務的運行狀態。

[ec2-user@ip-172-31-14-20 ~]$ sudo systemctl status docker.service
● docker.service - Docker Application Container Engine
     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: disabled)
     Active: active (running) since Tue 2023-06-13 06:03:58 UTC; 2min 43s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
    Process: 3521524 ExecStartPre=/bin/mkdir -p /run/docker (code=exited, status=0/SUCCESS)
    Process: 3521525 ExecStartPre=/usr/libexec/docker/docker-setup-runtimes.sh (code=exited, status=0/SUCCESS)
   Main PID: 3521526 (dockerd)
      Tasks: 7 (limit: 1125)
     Memory: 32.0M
        CPU: 308ms
     CGroup: /system.slice/docker.service
             └─3521526 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --default-ulimit nofile=32768:65536

Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.331901121Z" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}" module=grpc
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.331984523Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.334355857Z" level=error msg="Failed to built-in GetDriver graph btrfs /var/lib/docker"
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.370503275Z" level=info msg="Loading containers: start."
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.634911582Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.761644080Z" level=info msg="Loading containers: done."
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.883279682Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=overlay2 version=20.10.17
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.883634538Z" level=info msg="Daemon has completed initialization"
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal systemd[1]: Started docker.service - Docker Application Container Engine.
Jun 13 06:03:58 ip-172-31-14-20.ap-northeast-1.compute.internal dockerd[3521526]: time="2023-06-13T06:03:58.918898852Z" level=info msg="API listen on /run/docker.sock"


沒有留言:

張貼留言