linux怎么查看本机内存大小
270
2022-10-22
docker镜像创建 2 ——实战(SSHD、LNMP)
实验1 构建ssh镜像容器
#创建sshd的工作目录
mkdir /opt/sshd
cd /opt/sshd
vim Dockerfile
.............................................
#第一行必须指明基于的基础镜像
FROM centos:7
#作者信息.
MAINTAINER this is ssh image
构建完成sshd的容器后,下面再容器中构建sshd的Systemctl镜像来查看信息状态
#创建systemctl
mkdir /opt/systemctl
cd /opt/systemctl
vim Dockerfile
.....................................
FROM sshd:centos
MAINTAINER this is systemctl image
实验 构建docker容器-LNMP(实战项目)
环境:(docker ip)192.168.100.1 nginx doc01192.168.100.2 mysql doc02192.168.100.3 php doc03默认所有机器关闭防火墙、配好yum
```html/xml首先部署nginx#部署自定义网络,部署nginx(容器IP 为 192.168.100.1#容器ip是容器ip,ens33实体网卡ip是另外一个ip,别搞混了!!!docker network create --subnet=192.168.100.0/24 --opt "com.docker.network.bridge.name"="docker1" mynetwork
#创建工作目录mkdir /opt/nginxcd /opt/nginx/
#上传 nginx-1.12.0.tar.gz、wordpress-4.9.4-zh_CN.tar.gz、nginx.conf配置文件 到 /opt/nginx/ 目录中
mkdir /opt/nginx/html #创建相应文件给nginx解压tar zxvf wordpress-4.9.4-zh_CN.tar.gz -C /opt/nginx/html
vim Dockerfile.........................................................
FROM centos:7MAINTAINER this is nginx image
.............................................................#创建nginx镜像docker build -t nginx:lnmp .
#运行容器docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html --net mynetwork --ip 192.168.100.1 nginx:lnmp
提示:如果没现成配置文件,自己改修改nginx配置文件(与php的docker IP对接)在本机或者其他主机安装nginx,把nginx配置文件移进本机vim nginx.conf...location / {root html;index index.html index.php;}...location ~ .php$ {root html(这行修改!) fastcgi_pass 172.18.0.30:9000; fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;include fastcgi_params;}...
首先是创建自定义网络,然后创建nginx的工作目录,然后切换进去吧nginx-1.12.0.tar.gz、wordpress-4.9.4-zh_CN.tar.gz、nginx.conf配置文件传进去(nginx.conf自己先配好)
![1.png](https://s2./images/20220309/1646833437184496.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
随后我们创建相应文件给nginx解压,解压文件即可
![2.png](https://s2./images/20220309/1646833506975415.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
下面是在 /opt/nginx/里创建dockerfile文件
![3.1.png](https://s2./images/20220309/1646833556144569.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
成功创建镜像文件
![3.png](https://s2./images/20220309/1646833587310035.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![3.2.png](https://s2./images/20220309/1646833591834327.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
运行镜像,然后就把他运行起来就行
![4.png](https://s2./images/20220309/1646833608871090.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
```html/xml
下面我们创建mysql-docker02
192.168.100.2
#部署mysql(容器IP 为 192.168.100.2)
mkdir /opt/mysqld
cd /opt/mysqld
上传 mysql-boost-5.7.20.tar.gz 和mysql.conf到 /opt/mysqld 目录中
vim Dockerfile
........................
FROM centos:7
MAINTAINER this is mysql image
```html/xml#部署php(容器IP 为 192.168.100.3)
mkdir /opt/phpcd /opt/php
上传 php-7.1.10.tar.bz2 到 /opt/php 目录中
vim Dockerfile
。。。。。。。。。。。。。。FROM centos:7MAINTAINER this is php image
然后是vim php.ini修改mysqli.default_socket = /usr/local/ mysqL/mysqL.sock 修改 date. timezone = Asia/Shanghai
最后是 vim conf修改:user= nginxgroup = nginx
linten = 172.18.0.30:9000 (php)
#创建镜像docker build -t php:lnmp .#自定义网络docker run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --net mynetwork --ip 192.168.100.3 php:lnmp
最后一步:进入mysql授权docker exec -it mysql /bin/bash
mysqlcreate database wordpress;grant all privileges on wordpress. to 'wordpress'@'%' identified by '123456';grant all privileges on .* to 'root'@'%' identified by 'abc123';flush privileges;
浏览器访问:http://192.168.206.3/wordpress/index.php
![1.png](https://s2./images/20220310/1646892499795665.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 制作dockerfile文件 ![2.png](https://s2./images/20220310/1646892504767799.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 运行镜像 ![2.1.png](https://s2./images/20220310/1646892519512285.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![3.png](https://s2./images/20220310/1646892529832450.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 运行容器 ![4.png](https://s2./images/20220310/1646892535949912.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 制作mysql数据库 ![5.png](https://s2./images/20220310/1646892546480783.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) 刷新数据库 ![5.1.png](https://s2./images/20220310/1646892557661782.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ![5.2.png](https://s2./images/20220310/1646892565953237.png?x-oss-process=image/watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) #浏览器访问 http://192.168.206.3/wordpress/index.php 即可
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~