dockerfile构建nginx镜像
[root@docker ~] vim Dockerfile
FROM centos:7
RUN rm -rf /etc/yum.repos.d/*
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d/
RUN yum -y install nginx
EXPOSE 80
CMD ["/usr/sbin/nginx","-g","daemon off;"]
[root@docker ~] docker build -t nginx:v1 .
[root@docker ~] docker container prune
[root@docker ~] docker run -itd --name nginx -p 88:80 nginx:v1
949990a5d00de424084e5a169e03faf3f76cfd0baf626e97d9f1b1ec2ef8858a
[root@docker ~] docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
949990a5d00d nginx:v1 "/usr/sbin/nginx -g …" 2 seconds ago Up 1 second 0.0.0.0:88- >80/tcp, :::88->80/tcp nginx
[root@docker ~] docker exec -it 949990a5d00d(CONTAINER ID) /bin/bash
[root@949990a5d00d /] cd /usr/share/nginx/
[root@949990a5d00d nginx] ls
html modules
[root@949990a5d00d nginx] cd html/
[root@949990a5d00d html] ls
404.html 50x.html en-US icons img index.html nginx-logo.png poweredby.png
[root@949990a5d00d html] rm -rf index.html
[root@949990a5d00d html] echo abc > index.html
使用浏览器访问http://192.168.100.10:88
扫雷案例
1、在docker主机中部署apache服务,并将saolei.zip放置到该站点中,使其通过http://docker主机ip/saolei.zip可以下载
[root@docker] yum -y install httpd
2、将Centos-7.repo和epel-7.repo文件上传至/root目录
[root@docker] ls /root/
Centos-7.repo epel-7.repo
3、# 将saolei.zip包放置/目录下
[root@docker ~] rz -E
rz waiting to receive.
4、新建dockerfile
[root@docker] vim Dockerfile
FROM centos:7
RUN rm -rf /etc/yum.repos.d/*
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d/
RUN yum -y install tomcat unzip
WORKDIR /var/lib/tomcat/webapps/
ADD saolei.zip .
RUN unzip saolei.zip && mv saolei ROOT
ADD init.sh /init.sh
EXPOSE 8080
CMD ["bin/bash","/init.sh"]
5、新建init.sh脚本
[root@docker] vim init.sh
/usr/libexec/tomcat/server start
6、构建saolei:v1镜像
[root@docker] docker build -t saolei:v1 .
7、# 运行saolei容器
[root@docker] docker run -itd --name saolei -P saolei:v1
8ab87465634a8709d1a335ffb5c4f3fb83ea0d33cb25ff684c818fffb8e6df18!

可道云案例
[root@docker opt] mkdir dockerfile
[root@docker opt] cd dockerfile
[root@docker dockerfile] mkdir kod
[root@docker dockerfile] cd kod/
[root@docker kod] ls
dockerfile kodexplorer4.40.zip nginx.conf Centos-7.repo epel-7.repo
[root@docker kod] cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /code;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /code;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /code$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@docker kod] vim dockerfile
FROM centos:7
RUN rm -rf /etc/yum.repos.d/*
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d/
RUN yum -y install nginx php-fpm php-gd php-mbstring unzip
RUN sed -i '/^user/c user=nginx' /etc/php-fpm.d/www.conf
RUN sed -i '/^group/c group=nginx' /etc/php-fpm.d/www.conf
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir /code
WORKDIR /code
COPY kodexplorer4.40.zip . RUN unzip kodexplorer4.40.zip
RUN chown -R nginx.nginx . ADD init.sh /init.sh
EXPOSE 80
ENTRYPOINT ["/bin/bash","/init.sh"]
[root@docker kod] vim init.sh
php-fpm -D
echo "$1" >> /etc/nginx/nginx.conf
nginx -g 'daemon off;'[root@docker01 kod] docker build -t kod:v3 .
[root@docker01 kod] docker run -d -p 80:80 kod:v3 '#testtest' a9eb681a966288797d5fe096d035ae7d1649b20216d1f844cfd7bb1f0abb81c9
