LoginSignup
3
2

More than 5 years have passed since last update.

docker on ec2

Last updated at Posted at 2016-07-16

docker on ec2

気になってたけど、全然やれてなかったdocker
少し動かすだけだとそこまで時間かからなかったので
もうすこしはやくさわっておけばよかったとおもった。
少しでも誰かの役に立てばうれしい。

参考:https://docs.docker.com/engine/installation/linux/rhel/
1.確認

sudo su -
uname -r

2.yum update

yum update

3.yumリポジトリ情報の作成

tee /etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

4.dockerのinstall
yum install docker-engine

5.dockerServiceの起動
service docker start

6.Testイメージ?の起動
docker run hello-world

7.ubuntuのImageからhello world
参考:https://docs.docker.com/engine/tutorials/dockerizing/

docker run ubuntu /bin/echo 'Hello world'

★このとき、コンテナはどうなっているのだろう(実行して落ちてる?実行後も動いてる)?
以下らしい。コマンドを実行したら停止
So what happened to the container after that?
Well, Docker containers only run as long as the command you specify is active.
Therefore, in the above example, the container stops once the command is executed.

8.インタラクティブ(対話的)に実行
docker run -t -i ubuntu /bin/bash

9.httpdをコンテナにいれて起動してつないで見る
これが一番最初にやりたかったこと。

hello worldでやったようにCentOSを起動
※systemdを静かに避け、centos6を入れる
docker run -t -i centos:centos6 /bin/bash
普通にyumでhttpdをinstallする
yum install httpd -y

chkconfig httpd on
/etc/init.d/httpd start
netstat -an | grep httpd
ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0

ps -aux | grep http
echo "docker test" >> /var/www/html/index.html

10.HostOS側での操作

docker commit reverent_bardeen centoshttpd
docker run -i -t -p 50050:80 centoshttpd /bin/bash

11.コンテナでの操作
chkconfig httpd on
/etc/init.d/httpd start

curl http://localhost
docker test
exit

curl http://localhost:50050
curl: (7) Failed connect to localhost:50050; Connection refused

※Exitで抜けたら上手く行かなかった

docker run -i -t -p 50050:80 centoshttpd /bin/bash

chkconfig httpd on

/etc/init.d/httpd start

curl http://localhost:50050
docker test

curl http://localhost:50050/index.html
docker test

Ctrl+P,Qでコンテナから抜ける

12.ELB配下において設定
50050でコンテナの80にPortForwardするので
hostOS側の50050をhealthcheckPortにして組み込む

13.接続確認OK

3
2
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
3
2