dockerfile 案例
扫雷
开机自启
[root@a1 ~]# mount .dev/cdrom /mnt/
mount: /mnt: special device .dev/cdrom does not exist.
[root@a1 ~]# yum -y install httpd
[root@a1 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
上传软件包
[root@a1 html]# rz -E
rz waiting to receive.
[root@a1 html]# ls
saolei.zip
[root@a1 html]# ll
total 244
-rw-r--r--. 1 root root 247278 Aug 29 11:03 saolei.zip
防火墙
[root@a1 ~]# systemctl stoop firewalld
Unknown operation stoop.
[root@a1 ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@a1 ~]# vi /etc/selinux/config
SELINUX=disabled
部署dockerfile
在二号上部署
[root@a2 ~]# rz -E
rz waiting to receive.
[root@a2 ~]# ls
anaconda-ks.cfg Centos-7.repo epel-7.repo
编辑dockerfile
[root@a2 ~]# vi Dockerfile
FROM centos:7
MAINTAINER guanbingjie@example.com
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d/
RUN yum install -y tomcat unzip curl
WORKDIR /var/lihnjb/tomcat/webapps/
RUN curl -O http://192.168.87.128/saolei.zip && \
unzip saolei.zip && \
mv saolei ROOT
ADD init.sh /init.sh
EXPOSE 8080
CMD ["/bin/bash","/init.sh"]
[root@a2 ~]# vi init.sh
#!/bin/bash
/usr/libexec/tomcat/server start
构建镜像
[root@a2 ~]# docker build -t saolei:z1 .
Successfully built ec59abc3dc33
Successfully tagged saolei:z1
运行容器
[root@a2 ~]# docker run -d --name guanbingjie -p 8081:8080 saolei:z1
f9c602b7321089cdcd344d290da6586c5ff579898308f7da732a4675d4488478
[root@a2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9c602b73210 saolei:z1 "/bin/bash /init.sh" 7 seconds ago Up 6 seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp guanbingjie
可道云
文件传入虚拟机
[root@a2 ~]# rz -E
rz waiting to receive.
[root@a2 ~]# rz -E
rz waiting to receive.
[root@a2 ~]# ls
anaconda-ks.cfg Dockerfile init.sh kodexplorer4.40.zip nginx.txt
文件放在/opt/dockerfile/kod/下
[root@a2 ~]# mkdir -p /opt/dockerfile/kod
[root@a2 ~]# cd /opt/dockerfile/kod/
[root@a2 kod]# cp /root/* /opt/dockerfile/kod/
[root@a2 kod]# mv nginx.txt nginx.conf
[root@a2 kod]# ls
anaconda-ks.cfg Dockerfile init.sh kodexplorer4.40.zip nginx.conf
编辑dockerfile
[root@a2 kod]# vim dockerfile
FROM centos:7
ADD Centos-7.repo /etc/yum.repos.d/
ADD epel-7.repo /etc/yum.repos.d/
RUN yum install -y nginx php-fpm php-gb php-mbstring unzip && \
sed -i '/^user/c user=nginx' /etc/php-fpm.d/www.conf && \
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 && \
chown -R nginx.nginx .
ADD init.sh /init.sh
EXPOSE 80
ENTRYPOINT ["/bin/bash","init.sh"]
[root@a2 kod]# vim init.sh
#!/bin/bash
php-fpm -D
echo "$1" >> /etc/nginx/nginx.conf
nginx -g 'daaemon off;'
构建镜像
[root@a2 kod]# docker build -t kod:v1 .
Successfully built fdb7b90b22ee
Successfully tagged kod:v1
运行容器
[root@a2 a]# docker run --name guanbingjie -d -p 80:80 dok:v1
c9dae915a52fa54dc7faccbbe3fb4aa5385d919c6d13e0773b73d52678282eec