Dockerfile基本使用

									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
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值