Last active
February 13, 2019 23:01
-
-
Save seraphy/0b7cd9f9b9d264873fc5d95783f2c715 to your computer and use it in GitHub Desktop.
DockerのCentOS7 + Apache/2.4.6 (CentOS) PHP/5.4.16 + SSHD の仮想マシン
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| * text=auto | |
| *.sh text eol=lf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM centos:centos7 | |
| ################################################################### | |
| # | |
| # CentOS7 + Apache/2.4.6 (CentOS) PHP/5.4.16 + SSHD の仮想マシン | |
| # | |
| # [参考/元ネタ] | |
| # http://momijiame.tumblr.com/post/125344790446/ | |
| # https://www.itmedia.co.jp/enterprise/articles/1602/17/news004.html | |
| # | |
| # [使い方] | |
| # | |
| # 起動方法: | |
| # | |
| # docker run -it -d -p 2222:22 -p 8888:80 --name httpd centos7httpd | |
| # docker run -it -d -p 2222:22 -p 8888:80 -v /c/Users/Public/htdocs:/var/www/html --name httpd centos7httpd | |
| # ※ Windows版DockerToolboxはVirtualBoxの設定でC:\Users\の下が/c/Users/で共有可能になっている | |
| # | |
| # シェルへの入り方: | |
| # docker exec -it httpd /bin/bash | |
| # | |
| # 環境変数の設定方法 | |
| # (WindowsのDocker Toolboxの場合) | |
| # docker-machine env --shell cmd で設定する環境変数をプリント | |
| # docker-machine ip でアドレス取得 | |
| # | |
| # FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd') DO @%i | |
| # FOR /f "tokens=*" %i IN ('docker-machine ip') DO SET DOCKER_IP=%i | |
| # | |
| # SSHのつなぎ方: | |
| # ssh -l root -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 %DOCKER_IP% | |
| # | |
| # HTTPのつなぎ方・確認: | |
| # curl http://%DOCKER_IP%:8888 | |
| # | |
| # 停止・起動を繰り返すとDocker-Machineがおかしくなりやすいので | |
| # docker: Error response from daemon: cgroups: cannot find cgroup mount destination: unknown. | |
| # そのときは docker-machine restart してDocker仮想マシンを再起動させる。 | |
| # (上記環境変数が変わる可能性がある。) | |
| # | |
| ################################################################### | |
| RUN yum -y update && yum clean all | |
| # 古いネットツール(ifconfigとか) | |
| RUN yum -y install net-tools | |
| # Apache2.4 | |
| RUN yum -y install httpd | |
| # php5.4 | |
| RUN yum -y install php | |
| # index.phpの作成 | |
| RUN echo "<?php phpinfo()?>" > /var/www/html/index.php | |
| # apache の使うポートを公開する | |
| EXPOSE 80 | |
| # OpenSSHをインストールする | |
| RUN yum -y install openssh-server | |
| RUN yum -y install openssh-clients | |
| # root でログインできるようにする | |
| RUN sed -ri 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config | |
| # root のパスワードを 設定 | |
| RUN echo 'root:password' | chpasswd | |
| # 使わないにしてもここに公開鍵を登録しておかないとログインできない | |
| RUN ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key | |
| # sshd の使うポートを公開する | |
| EXPOSE 22 | |
| # httpdとsshdを起動するスクリプト | |
| COPY startup.sh /startup.sh | |
| RUN chmod 755 /startup.sh | |
| # 起動する | |
| CMD ["/startup.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 起動日時のログ | |
| date > /var/startup.log | |
| # HTTPDの開始 (バックグラウンド) | |
| /usr/sbin/httpd -k start &>> /var/startup.log | |
| # SSHDをフォアグランドで開始 (つまり、ここで終わらせない) | |
| /usr/sbin/sshd -D &>> /var/startup.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment