facebook twitter hatena line email

「仮想サーバ/docker」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(docker内のapacheでphpを動作させる)
行80: 行80:
 
==docker内のapacheでphpを動作させる==
 
==docker内のapacheでphpを動作させる==
 
  $ docker-machine ip #ipを確認しておく(192.168.99.101)
 
  $ docker-machine ip #ipを確認しておく(192.168.99.101)
  $ docker pull jdeathe/centos-ssh-apache-php # apache-php付きのコンテナを持ってくる
+
  $ docker pull jdeathe/centos-ssh-apache-php # apache-php付きのimageを持ってくる
 
  $ docker run -it --publish 80:80 jdeathe/centos-ssh-apache-php:latest /bin/bash # 起動&80port開放
 
  $ docker run -it --publish 80:80 jdeathe/centos-ssh-apache-php:latest /bin/bash # 起動&80port開放
 
  [root@8ff8c5a8cb27 /]# /etc/rc.d/init.d/httpd start
 
  [root@8ff8c5a8cb27 /]# /etc/rc.d/init.d/httpd start

2016年2月16日 (火) 02:33時点における版

macにdockerをインストール

Docker Toolboxをインストール https://www.docker.com/products/docker-toolbox (boot2dockerは非推奨らしい)

インストール確認

$ docker -v
Docker version 1.10.0, build 590d5108
$ docker-machine -v
docker-machine version 0.6.0, build e27fb87

コンテナ作成

defaultという名前でvmが起動する(virtualbox用)

docker-machine create --driver virtualbox default

vm一覧

$ docker-machine ls
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.10.0

起動

docker-machine start default

ログイン

docker-machine ssh default

停止・削除・ip

docker-machine stop default # 停止
docker-machine rm default # 削除
docker-machine ip default # ip (192.168.99.100)

docker検索

$ docker search centos
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                          The official build of CentOS.                   1911      [OK]
jdeathe/centos-ssh              CentOS-6 6.7 x86_64 / SCL/EPEL/IUS Repos /...   15                   [OK]
jdeathe/centos-ssh-apache-php   CentOS-6 6.7 x86_64 / Apache / PHP / PHP M...   13                   [OK]
padster83/centos7-php7-laravel5   centos7 php7 and larvel5.1                      4                    [OK]

dockerイメージ取得(centos6.7)

dockerにログインしてから

$ docker pull jdeathe/centos-ssh
Using default tag: latest
latest: Pulling from jdeathe/centos-ssh
a3ed95caeb02: Pull complete
3b231ed5aa2f: Pull complete
739732e8a1eb: Pull complete
4748cf13cce1: Pull complete
b43cafb7f42b: Pull complete
ecc6934ef96a: Pull complete
d258b8324b77: Pull complete
0bf7d359e07c: Pull complete
34a742724dd4: Pull complete
646a068632d8: Pull complete
a9397714f8e2: Pull complete
4b0007b85fa0: Pull complete
40cbdf152dd2: Pull complete
a9a0656572df: Pull complete
Status: Downloaded newer image for jdeathe/centos-ssh:latest

取得したイメージの確認

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              61b442687d68        6 weeks ago         196.6 MB
jdeathe/centos-ssh              latest              09cc921e8147        6 days ago          253.3 MB

作成したコンテナの中に入る

docker run -it jdeathe/centos-ssh:latest /bin/bash

コンテナの確認

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                              PORTS               NAMES
e831d68bfbe7        centos:latest       "/bin/bash"              20 minutes ago      Exited (0) Less than a second ago                       drunk_ride

コンテナの削除

docker rm e831d68bfbe7

docker pullでDownloading...のまま止まった時

”docker-machine stop"で停めてdocker-machineを再作成する

docker内のapacheでphpを動作させる

$ docker-machine ip #ipを確認しておく(192.168.99.101)
$ docker pull jdeathe/centos-ssh-apache-php # apache-php付きのimageを持ってくる
$ docker run -it --publish 80:80 jdeathe/centos-ssh-apache-php:latest /bin/bash # 起動&80port開放
[root@8ff8c5a8cb27 /]# /etc/rc.d/init.d/httpd start

ローカルマシンからhttp://192.168.99.101へアクセスすると画面が開く

iso場所

/Users/user1/.docker/machine/machines/dev/boot2docker.iso