LoginSignup
4
2

More than 5 years have passed since last update.

Dockerメモ

Last updated at Posted at 2016-10-06

Dockerメモ

Dockerについて勉強したので、メモ。

Dockerとは?

2016年版、Dockerのすべてが5分でわかるまとめ!(コマンド一覧付き)
簡単にWebサーバーとかDBサーバーとかの開発環境を作れる。
この作った環境を、簡単に本番環境にも作れるので、開発環境と本番環境が同一となる。

Vagrantと何が違うの?

dockerとvagrantの違い言える?新人エンジニアでも分かった気になれる俺流まとめ
DockerはLinux上でしか動かない。
なので、macで使う場合、VagrantでLinuxを立ち上げて、そこでDockerを動かす必要がある。
実際に使う時は、Docker for Mac使うのが楽。
Public BetaになったDocker for Macを使ってみる

Docker使用例

Docker-composeっていうのを使ってます。
これを使うと、コマンド一個でいろいろ立ち上がるので楽です。

LAMP環境作成

Docker Composeを使ってLAMP環境を立ち上げる

Dockerコンテナに入る方法

$ docker exec -it コンテナ名 bash

Localのソースを使いたい場合

https://github.com/naga3/docker-lamp.git の docker-compose.yml を修正。

docker-compose.yml
volumes:
//  - ./html:/var/www/html -> 左側がlocal環境、右側がコンテナ内。ここを自分の環境見ながら修正
- ~/Code/php:var/www/html //->こうやると、~/Code/php内のファイルをlocalhostで参照できる。

apacheサーバのリスタート

$ docker-compose restart

停止したい時は、$ docker-compose downだけで。
コマンド一覧は、こちらdocker-compose コマンドまとめ

次目指すこと

いまのところなし。

Selenium稼働環境作成

Running a Selenium Grid with docker-compose

mkdir selenium-docker
cd selenium-docker
vi docker-compose.yml
docker-compose up -d
docker-compose.yml
hub:
  image: selenium/hub
  ports:
    - "4444:4444"
firefox:
  image: selenium/node-firefox
  links:
    - hub
chrome:
  image: selenium/node-chrome
  links:
    - hub

これで、 http://localhost:4444/grid/console にアクセスしたら、なんか出ると成功。

テストファイル作成

$ mkdir jstest
$ vi package.json
$ npm -g install mocha
$ npm install --save-dev selenium-webdriver
$ npm install --save-dev expect.js
$ vi test.js
$ mocha test.js --timeout 20000
test.js
var webdriver = require('selenium-webdriver');
var t = require('selenium-webdriver/testing');
var expect = require('expect.js');
var driver;
var assert = require('assert');
var By = webdriver.By;

t.describe('テスト', function () {
  t.before(function () {
    driver = new webdriver.Builder().usingServer('http://localhost:4444/wd/hub')
      .withCapabilities(webdriver.Capabilities.chrome()).build();
  });

  t.after(function () {
    driver.quit();
  });

  t.it('テスト1', function () {
    driver.get('http://example').then(function () {
      driver.findElement(By.className('btnYes')).click();
      driver.findElement(By.className('btnYes')).click();
      driver.findElement(By.className('btnYes')).click();
      driver.findElement(By.className('btnYes')).click();

      //エラーメッセージを取得して、文言が正しいかチェックする
      var parent = driver.findElement(By.className("test"));
      driver.wait(parent.findElement(By.tagName("a")).getText(), 1000)
        .then(function (text) {
          expect(text).to.be('テストです');
        });
    });
  });
});

テスト時のスクリーンショット保存

https://github.com/keisukeponpoko/selenium-test-base
これを使えばできる。

次目指すこと

上記を使えば、Linux環境上で、chromeとFirefoxでのブラウザテストができる。
残り
・テスト速度を早くするために、並列実行。
Docker で Selenium Grid による並列実行環境を構築

・実機を準備して、スマホや、mac、Windows環境でもテストできるように
http://www.techscore.com/blog/2015/05/10/selenium-grid/
を目指す。

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