2
1

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は環境の再現性が強みというわけで、今回はDocker For WindowsDocker for Macの両方で試しました。

たぶんLinux環境下ではMac(bash)と同じです。

環境

Windows (PowerShell)

PowerShell
> [System.Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.16299.0 Microsoft Windows NT 10.0.16299.0

> docker --version
Docker version 17.09.0-ce, build afdb6d4

Mac(bash)

bash
$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.11.6
BuildVersion:	15G31

$ docker --version
Docker version 17.06.2-ce, build cec0b72

構築

まずDockerfile を用意します。

Dockerfile
FROM php:7.2-rc
WORKDIR /root

次にビルドします。

PowerShell/bash
> docker build . --tag example_php_72rc

これで完成です。お疲れ様でした。

確認

イメージができているか確認します。

PowerShell
> docker images | Select-String example_php_72rc

example_php_72rc            latest              474bd1d2c30a        3 minutes ago       354MB

なお、Windows PowerShellにおけるSelect-String は、Mac/Linuxなら grep を使います。

bash
$ docker images | grep example_php_72rc
example_php_72rc               latest              75a229bbc39e        About a minute ago   354MB

いずれも、イメージができていることが確認できました。

php --versionphp --run 'echo phpinfo();' を使ってPHPのバージョンを確認します。

PowerShell
> docker run --rm example_php_72rc php --version
PHP 7.2.0RC4 (cli) (built: Oct 12 2017 22:09:58) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0-dev, Copyright (c) 1998-2017 Zend Technologies
bash
$ docker run --rm example_php_72rc php --run 'echo phpinfo();' | grep 'PHP Version'
PHP Version => 7.2.0RC4
PHP Version => 7.2.0RC4

RC版7.2になっていることがわかります。

実行

ボリュームをマウントすれば、ファイルを実行できます。

index.phpを作成し、実行してみます。

index.php
<?php
echo 'Hello, PHP7.2!';

Windows

PowerShell
> docker run --volume "$(pwd):/root" --rm example_php_72rc php index.php
Hello, PHP7.2!

Mac

bash
$ docker run --volume `pwd`:/root --rm example_php_72rc php index.php
Hello, PHP7.2!

LAMP等でWebサーバにするためにはもう少し手順を踏まないといけないのですが、ただプログラムを動かすだけならばここまで簡単に環境を用意することができます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?