docker容器ubuntu安装apache+php

查看当前路径以及目录

[root@test-devops apache_ubuntu]# pwd

/home/docker/apache_ubuntu

[root@test-devops apache_ubuntu]# tree

.

├── Dockerfile

├── run.sh

└── sample

    ├── index.html

    └── index.php



1 directory, 4 files

[root@test-devops apache_ubuntu]#

查看dockerfiler

[root@test-devops apache_ubuntu]# cat Dockerfile

# 继承的镜像

FROM sshd/ubuntu

# 作者信息

MAINTAINER from steven (www.opsnotes.net)

# set env
ENV DEBIAN_FRONTEND noninteractive


# install

#RUN apt-get -yq install apache2 && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get -y install apache2 php5 php5-cli libapache2-mod-php5 php5-gd php5-json php5-ldap php5-mysql php5-pgsql

#RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata


# add scripts

ADD run.sh /run.sh

RUN chmod +x /*.sh

# add web site

RUN rm -rf /var/www/html/*

COPY sample/ /var/www/html/


# set apache env

ENV APACHE_RUN_USER www-data

ENV APACHE_RUN_GROUP www-data

ENV APACHE_LOG_DIR /var/log/apache2

ENV APACHE_PID_FILE /var/run/apache2.pid

ENV APACHE_RUN_DIR /var/run/apache2

ENV APACHE_LOCK_DIR /var/lock/apache2

ENV APACHE_SERVERADMIN admin@opsnotes.net

ENV APACHE_SERVERNAME localhost

ENV APACHE_SERVERALIAS docker.localhost

ENV APACHE_DOCUMENTROOT /var/www

EXPOSE 80

CMD ["/run.sh"]

[root@test-devops apache_ubuntu]#

允许脚本文件

[root@test-devops apache_ubuntu]# cat run.sh

#!/bin/bash

/usr/sbin/sshd & /usr/sbin/apache2ctl -D FOREGROUND

[root@test-devops apache_ubuntu]#

php配置文件

[root@test-devops apache_ubuntu]# cat sample/index.html sample/index.php

Hello docker for apache2

<?php

  phpinfo();

?>

[root@test-devops apache_ubuntu]#

编译镜像文件

[root@test-devops apache_ubuntu]# docker build -t apache/ubuntu .

Sending build context to Docker daemon  5.12 kB

Sending build context to Docker daemon

Step 0 : FROM sshd/ubuntu

 ---> 2174ff805e24

Step 1 : MAINTAINER from steven (www.opsnotes.net)

 ---> Running in 946827c66499

 ---> 1ec0466c830a

Removing intermediate container 946827c66499

Step 2 : ENV DEBIAN_FRONTEND noninteractive

 ---> Running in e85fd7b1892b

 ---> ba74f7850867



……略……

Step 21 : CMD /run.sh

 ---> Running in 2f5ba56d544a

 ---> 836de7d05dae

Removing intermediate container 2f5ba56d544a

Successfully built 836de7d05dae

[root@test-devops apache_ubuntu]#

查看docker镜像

[root@test-devops apache_ubuntu]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

apache/ubuntu       latest              1067e5fa37b5        6 minutes ago       328.2 MB

[root@test-devops apache_ubuntu]#

允许docker镜像指定端口以及映射

[root@test-devops apache_ubuntu]# docker run -d -p 10122:22 -p 888:80 apache/ubuntu

fbec71123106b2812d552f17cbb485b9d998209a39efe908ae5d74dcc03341bf

[root@test-devops apache_ubuntu]#

登陆查看是否成功

[root@test-devops apache_ubuntu]# docker-enter fbe

root@fbec71123106:~# netstat -tlnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9/apache2

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      10/sshd

root@fbec71123106:~# logout

[root@test-devops apache_ubuntu]#
OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!