查看当前路径以及目录
[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
e>
允许脚本文件
[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]#