(实验准备1台虚拟机--网络yum源)
1号机#
#桥接网络例如ip:192.168.1.10
#ifdown ens33;ifup ens33
#systemctl stop firewalld
#setenforce 0
#yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#yum -y install docker
# ystemctl start docker \\启动
#systemctl enable docker \\设为开机自动启动
#docker version \\查看docker版本
#docker pull docker.io/centos //下载centos
#docker images
#docker save -o centos docker.io/centos //将docker.io/ceonts改名为centos
#docker load --input centos //将centos上传到本地镜像
#mkdir /root/nginx
#cd /root/nginx
#vim Dockfile
FROM centos
MAINTAINER THE
RUN yum -y install wget pcre-devel net-tools gcc zlib zlib-devel make openssl-devel tar
RUN wget http://nginx.org/download/nginx-1.16.0.tar.gz
RUN tar zxf nginx-1.16.0.tar.gz
WORKDIR nginx-1.16.0
RUN ./configure --prefix=/usr/local/nginx && make && make install
EXPOSE 80
EXPOSE 443
RUN echo "daemon off;" >> /usr/local/nginx/conf/nginx.conf
WORKDIR /root/nginx
ADD run.sh /run.sh
RUN chmod 775 /run.sh
CMD ["/run.sh"]
保存退出
#vim run.sh
添加:
#!/bin/bash
/usr/local/nginx/sbin/nginx
保存退出
#docker build -t nginx:wyjx . .、//构建镜像
#docker images
#docker run -d -P(大P) nginx:wyjx .//运行容器,随机端口
#docker ps
#firefox http://192.168.0.100:32769 测试访问
构建tomcat容器
#mkdir /root/tomcat
#cd /root/tomcat
复制jdk到工作目录,并解压
#vim Dockerfile
添加:
FROM centos
MAINTAINER LHY
ADD jdk1.8.0_91 /usr/local/jdk-8u91
ENV JAVA_HOME /usr/local/jdk-8u91
ENV JAVA_BIN /usr/local/jdk-8u 91/bin
ENV JRE_HOME /usr/local/jdk-8u91/jre
ENV PATH $PATH:/usr/local/jdk-8u91/bin:/usr/local/jdk-8u91/jre/bin
ENV CLASSPATH /usr/local/jdk-8u91/jre/bin:/usr/local/jdk-8u91/lib:/usr/local/jdk-8u91/jre/lib/charsets.jar
RUN yum -y install wget
RUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz
RUN tar zxf apache-tomcat-8.5.51.tar.gz
RUN mv apache-tomcat-8.5.51 /usr/local/tomcat
EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]
保存退出
#docker build -t tomcat:wyjx . 构建镜像,在当前目录
#docker run -d --name wyjxtc -p 80:8080 tomcat:wyjx 启动容器
#firefox http://192.168.0.100 测试访问
构建Mariadb容器同mysql一样的
mkdir /root/mysql
cd /root/mysql
#vim Dockerfile 创建Dockerfile
添加:
FROM centos
MAINTAINER zly
RUN yum install mariadb-server mariadb -y
ENV MARIADB_USER root
ENV MARIADB_PASS yourpwd
ENV LC_ALL en_US.UTF-8
EXPOSE 3306
ADD db_init.sh /root/db_init.sh
RUN chmod 775 /root/db_init.sh && /root/db_init.sh
CMD ["mysqld_safe"]
保存退出
.创建初始化脚本
#vim db_init.sh
添加:
#!/bin/bash
mysql_install_db --user=mysql
sleep 3
mysqld_safe &
sleep 3
mysqladmin -u "$MARIADB_USER" password "$MARIADB_PASS"
mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "use mysql; grant all privileges on *.* to '$MARIADB_USER'@'%' identified by
'$MARIADB_PASS' with grant option;"
h=$(hostname)
# 设置用户密码
mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "use mysql; update user set password=password('$MARIADB_PASS') where user='$M
ARIADB_USER' and host='$h';"
# 创建默认数据库
#mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "CREATE DATABASE IF NOT EXISTS default_db DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
# 刷新权限
mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "flush privileges;"
保存退出
设置用户密码
#mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "use mysql; update user set password=password('$MARIADB_PASS') where user='$M
ARIADB_USER' and host='$h';"
刷新权限
mysql -u "$MARIADB_USER" -p"$MARIADB_PASS" -e "flush privileges;"
保存退出
构建Mariadb镜像
#docker build -t my-mariadb .
启动容器
#docker run -d --name mariadb -p 3306:3306 my-mariadb
#yum install mariadb-server mariadb -y //登录不上去可以安装服务mariadb
#mysql -h 192.168.0.102 -u root -p 3306 -pyouspass