Qiita Conference 2025

鹿野壮 (@tonkotsuboy_com)

アウトプットは最強の自己投資 〜発信が人生とキャリアを変えた話〜

13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerを動かしてみる on Amazon EC2(CentOS6.5)

Last updated at Posted at 2014-03-16

概要

homepage-docker-logo.png

2014/03/10に、Dockerの0.9がリリースされました。
http://blog.docker.io/2014/03/docker-0-9-introducing-execution-drivers-and-libcontainer/

LXCに依存しなくなるど、構成も変わったようなので、早速試してみます(といっても、そこまで意識する必要のあることはやっていないが)。
これまで、ローカルのVirtualBoxで試していたけど、せっかくなので、Amazon EC2上でやってみることにしました。

EC2インスタンスの生成

  • Dockerは、Ubuntsがメインのサポート対象になっていますが、今回はCentOSにしてみます。
  • 「AWS Marketplace」から「CentOS 6 (x86_64) - with Updates」を選択して、インスタンスを生成。
  • 最初に、現在のCentOSのバージョンを確認。
# cat /etc/redhat-release
CentOS release 6.4 (Final)
  • CentOSだと、6.5以降にしておかないと、いろいろ面倒になりそうなので、ひとまずUpdate。
# yum -y update
・・・
# cat /etc/redhat-release
CentOS release 6.5 (Final)
  • wgetがインストールされていないので、先に入れておく。
# yum -y install wget

Dockerのインストール

  • yumのリポジトリに、EPEL(RedHatの拡張パッケージ)を登録する。
# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
  • Dockerをインストールする。
# yum -y install docker-io
# chkconfig docker on
# docker -v
Docker version 0.8.1, build a1598d1/0.8.1
  • ん?「Docker version 0.8.1」!? どうやら、現時点ではまだ0.9は公開されていないようですね。
  • ということで、個別にダウンロードしてインストールする。
# wget http://dl.fedoraproject.org/pub/epel/testing/6/x86_64/docker-io-0.9.0-3.el6.x86_64.rpm
# rpm -Uvh docker-io-0.9.0-3.el6.x86_64.rpm
# docker -v
Docker version 0.9.0, build 2b3fdf2/0.9.0
  • これで、Docker0.9.0のインストールが完了。

Dockerで"Hello World"

  • Dockerを起動する。
# service docker start
  • Dockerが実行できることを確認する。コンソールに「Hello World」と表示されればOK。
# docker run centos /bin/echo "Hello World"
Hello World

Dockerの実行ユーザを作成

  • Dockerに限った話ではないですが、Dockerの操作を行うために、専用のユーザを作成しておく。
# useradd docker -g docker
# passwd docker
New password:
Retype new password:
  • dockerグループに所属されたことを確認する。
# id docker
uid=500(docker) gid=498(docker) groups=498(docker)
  • dockerユーザで、sudoを使えるようにする。
# visudo
  • docker ALL=(ALL) ALL の部分を追加する。
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
docker  ALL=(ALL)       ALL
  • これで、dockerユーザでsudoが実行できるようになったので、改めて、dockerユーザでDockerを実行する。
# su - docker
$ sudo service docker restart
$ docker run centos /bin/echo "Hello World"
Hello World
  • とりあえず、動くことは確認できた。

参考

13
13
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?