Dockerfile
使用dockerfile安装apache
(1)创建dockerfile
[root@centos01 ~]# vim /apche/Dockerfile
FROM hub.c.163.com/public/cents:6.7-tools
RUN rm -rf /etc/yum.repos.d/Centos-*
RUN wget -O /etc/yum.repos.d/CentoOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
RUN yum clean all
RUN yum -y install httpd
RUN echo “www.benet.com” > /var/www/html/index.html
CMD [“httpd”,"-DFOREGROUND"]
(2)使用dockerfile
[root@centos01 apache]# docker build -t httpd:v1.0 .
(3)运行apache容器
[root@centos01 ~]# docker run -it -d --name httpd -p 192.168.100.10:80:80/tcp httpd:v1.0
(5)验证
5、使用dockerfile安装nginx
(1)创建dockerfile
[root@centos01 ~]# vim /nginx/Dockerfile
FROM hub.c.163.com/public/cents:6.7-tools
RUN rm -rf /etc/yum.repos.d/Centos-*
RUN wget -O /etc/yum.repos.d/CentoOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
RUN yum clean all
RUN yum -y install epel-release pcre-devel zlib-devel gcc
ADD nginx-1.6.0.tar.gz /usr/src/
RUN useradd -M 0s /sbin/nologin nginx
WORKDIR /usr/src/nginx-1.6.0
RUN ./configure --prefix=/usr/local/nginx/ --user=nginx --with-http_stub_status_module && make && make install
RUN echo “daemou off;” >> /usr/local/nginx/conf/nginx.conf
ENV PATH /usr/local/nginx/sbin:$PARH
EXPOSE 80
CMD [“nginx”]
(2)使用dockerfile创建镜像
[root@centos01 nginx]# docker build -t nginx:v1.0 .
(3)使用nginx镜像生成容器
[root@centos01 ~]# docker run -it -d --name nginx -p 192.168.100.10:8080:80/tcp nginx:v1.0
(4)验证
5、使用dockerfile安装mysql
(1)创建dockerfile
[root@centos01 ~]# vim /mysql/Dockerfile
FROM hub.c.163.com/public/cents:6.7-tools
RUN rm -rf /etc/yum.repos.d/Centos-*
RUN wget -O /etc/yum.repos.d/CentoOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
RUN yum clean all
RUN yum -y install ncurses-devel libstdc+±devel gcc-c++
RUN groupadd mysql
RUN useradd =M -s /sbin/noligin -g mysql mysql
ADD cmake-2.8.6.tar.gz /usr/src/
ADD mysql-5.5.22.tar.gz /usr/src/
WORKDIR /usr/src/cmake-2.8.6
RUN ./configure && gmake && gmake install
WORKDIR /usr/src/mysql-5.5.22
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYCONFDIR=/etc && make && make install
RUN cp support-files/my-medium.cnf /etc/my.cnf
RUN chown -R mysql:mysql /usr/local/mysql
RUN cp support-files/mysql.server /etc/init.d/mysqld
RUN chmod +x /etc/init.d/mysqld
RUN chkconfig --add mysqld
RUN chkconfig --level 35 mysqld on
RUN ln -s /usr/local/mysql/bin/* /usr/local/bin/
RUN /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
ADD mysqld.sh /usr/local/mysql
RUN chmod +x /usr/local/mysql/mysqld.sh
EXPOSE 3306
CMD “/usr/local/mysql/mysqld.sh” && tail -f /dev/null
(2)创建启动mysql脚本
[root@centos01 ~]# vim /mysql/mysqld.sh
#!/bin/bash
/etc/init.d/mysqld start
(3)使用dockerfile创建mysql镜像
[root@centos01 ~]# docker build -t mysql:v1.0 .
(4)运行mysql容器
[root@centos01 ~]# docker run -it -d --name mysql -p 192.168.100.10:3306:3306 mysql:v1.0