LoginSignup
0
0

More than 1 year has passed since last update.

EC2にDocker

Posted at

教材

前提

VPCとサブネットは作成済み
sshでEC2ログイン出来るところまで
EC2はポートHTTP80番を全開で受け付ける
ssh用の22番もマイIPだけ受け付ける(作業用)

Windows10 テラターム

完成形

image.png

作業

①EC2にログインします

②sudo -y yum update

③sudo -y yum install docker

④ sudo service docker start
起動

⑤sudo docker info
起動確認

⑥mkdir hallodocker
作業ディレクトリを作って移動

⑦vi hello.html
表示するhtmlを作成 保存

⑧vi Dockerfile
イメージをつくるためにDockerfileを作成
※今回はnginxをインストールする

FROM nginx
COPY ./hello.html /user/share/nginx/html/

⑨sudo docker build -t hello-docker-ec2

⑩sudo docker run --rm -d -p 80:80 hello-docker-ec2
※コンテナ停止したらコンテナ消す
ブラウザから80番で待つ
名前をつける

⑪ sudo docker ps
※確認

※間違ったときは
docker stop コンテナID
としてコンテナ削除する
⑨からやり直す

⑫ブラウザにEC2のIPアドレスでアクセスできる
http://EC2のIP/hello.hIP/

所感

ファイルを作り間違えない
パスを間違えない

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