5
5

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.

Apache、PHPをDockerで作る

Posted at

これは何?

DockerでApache、PHP7.0のコンテナをチャチャッと作ったときのメモ。

内容

Dockerfileetc_apache2_conf-enabled_docker-php.confvar_www_html_index.phpを同じディレクトリに保存する。

Dockerfile

Dockerfile
FROM php:7.0-apache

COPY ./etc_apache2_conf-enabled_docker-php.conf /etc/apache2/conf-enabled/docker-php.conf
COPY ./var_www_html_index.php /var/www/html/
var_www_html_index.php
<?php phpinfo();
etc_apache2_conf-enabled_docker-php.conf
<FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch>

DirectoryIndex disabled
DirectoryIndex var_www_html_index.php index.php index.html

<Directory /var/www/>
  Options -Indexes
  AllowOverride All
</Directory>

コンテナを生成して動かす

今どこ?
$ ls -l
total 24
-rw-r--r--  1 xxx  yyy  171 Nov  5 11:27 Dockerfile
-rw-r--r--  1 xxx  yyy  233 Nov  5 11:26 etc_apache2_conf-enabled_docker-php.conf
-rw-r--r--  1 xxx  yyy   17 Nov  5 11:17 var_www_html_index.php
buildする
$ docker build --tag php70-apache ./
起動する
$ docker run -d --name php70-apache  -p 8080:80 php70-apache
必要とあらばContainer内をのぞく
$ docker container exec -ti php70-apache bash
ContainerIDを探す
$ docker ps --filter name=php70-apache
Apacheのログを表示する
$ docker logs [ContainerID] 
Containerを停止する
$ docker stop [ContainerID] 
Containerを削除する
$ docker rm [ContainerID] 
ImageIDを取得する
$ docker images php70-apache
ImageIDを取得する
$ docker rmi [ImageID]

Reference

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?