12
12

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 やってみる。

Last updated at Posted at 2014-08-11

事前準備

$ brew update
$ brew upgrade

インストール

$ brew install boot2docker

$ boot2docker version
Client version: v1.1.2
Git commit: a229ac1

$ docker -v
Docker version 1.1.2, build d84a070

dockerも同時にインストールされる

$ export DOCKER_HOST=tcp://192.168.59.103:2375

.bashrcとか.zshrcとかに書いておくと良さそう。

動かしてみる

boot2docker

$ boot2docker init    # initialize
$ boot2docker up      # start VM
$ boot2docker status  
running

Vagrant コマンドライク。
実際に Vagrant 上に VM が立ち上がる。
これで Mac でdockerコマンドが使える。

MySQL

$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql

nginx

$ docker run -d -p 80:80 dockerfile/nginx

dockerfile/nginx は https://registry.hub.docker.com/u/dockerfile/nginx/ のこと。(docker hub)
今回はもう用意されている image を使ってみる。
これでそれぞれの image をとってきて、コンテナが立ち上がってるっぽい。

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
mysql               latest              36e732ca2610        7 weeks ago         458.7 MB
dockerfile/nginx    latest              2a106d243809        12 weeks ago        604.7 MB

確認してみる

$ docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                         NAMES
0f7f0ee24200        mysql:latest              /entrypoint.sh mysql   4 seconds ago       Up 3 seconds        0.0.0.0:3306->3306/tcp        dreamy_kirch
e6a423d43b3e        dockerfile/nginx:latest   nginx                  12 minutes ago      Up 12 minutes       443/tcp, 0.0.0.0:80->80/tcp   suspicious_curie

動いてるっぽい

nginxはもちろんブラウザから確認できる
スクリーンショット 2014-08-12 0.51.02.png

中に入ってみる

$ boot2docker ssh
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
boot2docker: 1.1.0
             master : 086c429 - Fri Jul  4 01:08:20 UTC 2014

docker@boot2docker:~$ ps aux | grep mysql
 1381 999      mysqld --datadir=/var/lib/mysql --user=mysql --init-file=/tmp/mysql-first-time.sql
 1544 docker   grep mysql

docker@boot2docker:~$ ps aux | grep nginx
 1355 root     nginx: master process nginx
 1363 33       nginx: worker process
 1364 33       nginx: worker process
 1365 33       nginx: worker process
 1366 33       nginx: worker process
 1542 docker   grep nginx

とめてみる

コンテナを停止する

$ docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                         NAMES
0f7f0ee24200        mysql:latest              /entrypoint.sh mysql   37 minutes ago      Up 37 minutes       0.0.0.0:3306->3306/tcp        dreamy_kirch
e6a423d43b3e        dockerfile/nginx:latest   nginx                  49 minutes ago      Up 49 minutes       443/tcp, 0.0.0.0:80->80/tcp   suspicious_curie

$ docker stop 0f7  # コンテナのidを識別できればおk.
0f7

$ docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS              PORTS                         NAMES
e6a423d43b3e        dockerfile/nginx:latest   nginx               50 minutes ago      Up 50 minutes       443/tcp, 0.0.0.0:80->80/tcp   suspicious_curie

参考・引用

https://github.com/boot2docker/boot2docker
http://qiita.com/deeeet/items/ed2246497cd6fcfe4104

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?