0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DockerコンテナをAWS ECSに移行 その1 Docker Engineインストール

Last updated at Posted at 2024-02-22

きっかけ

 Dockerはすごく便利です。さらに便利になるよう、そのコンテナをマネージド利用するべく、ECS on Fargateに移行してみました。
構築手順の量が多く、特にECSの設定は間違いなく忘れる自身があります ^^;
最初のdocker構築からECS構築までの一連の流れについて、忘却の彼方へ記憶が飛ぶ前に、記録しておきたいと思いました

Qiitaの記事の構成、今回、次回、今後について

  • その1:今回の記事
    • Docker Engineインストール
  • その2:次回の記事
    • Docker Composeで、wordpress+mysqlを構築
  • その3:今後の記事
    • その2のDocker Compose構成を、ECS on Fargateに移行

構築の前提

  • 移行元マシン
    • AWS EC2 Ubuntu 20.04 LTS

dockerエンジン インストール手順

古いバージョンのアンインストール

$ sudo apt-get remove docker docker-engine docker.io containerd runc

リポジトリのセットアップ

$ sudo apt-get update
$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Docker の公式 GPG 鍵を追加

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

以下のコマンドを使って安定版(stable)リポジトリをセットアップ

$ 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

Docker Engine のインストール

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Docker Engine をhello-worldコンテナイメージで動作確認

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
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イメージの確認

$ sudo docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d2c94e258dcb   9 months ago   13.3kB

全てのコンテナ一覧(停止中のコンテナ含む)

$ sudo docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
20dda2dab55d   hello-world   "/hello"   7 minutes ago   Exited (0) 7 minutes ago             vibrant_beaver

次回に続く

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?