【Docker环境搭建】

一、云服务器的配置

1.概述:服务器----->看成是一台电脑(计算机)----->没有显示器,只有一台主机----->也需要操作系统环境配合

2.阿里云服务器:看成是一台没有显示器的电脑;

3.配置:集中在【控制台】;

​ 3.1>更改云服务器的操作系统

​ 1)先停止云服务器的运行;

​ 2)点击【更换操作系统】;

​ 3.2>重置云服务器系统的实例密码;

​ 实例密码:指的是云服务器系统的帐号匹配的密码,例:centos系统:账号:root---->密码

​ 3.3>finalshell工具:连接服务器/云服务器环境()
windows系统
finalshell工具(Windows)
MacOS系统
finalshell工具(MacOS)
Linux系统
finalshell工具(Linux)

二.Docker容器技术概述

1.docker是基于操作系统层面(安装在操作系统中使用)的一项虚拟化容器技术(类似于虚拟机)该工具给使用者提供了一个平台,在平台上有很多的容器(集装箱),在每一个容器中可以单独封装不同的项目和它所需要的使用环境,每个容器之间是相互独立,互不影响。

2.logo:鲸鱼货轮---->docker------>货轮上的集装箱---->docker提供的容器—>集装箱用来装货物---->容器封装项目环境

三、Docker和虚拟机的异同点;

1.相同点:基于操作系统层面的工具(安装);

不同点:虚拟机的使用,需要借助于第三方的软件,比如VM Player;

​ 虚拟机软件有了之后,还需要在软件中进行操作系统的安装,比如centos7;

​ 虚拟机操作系统环境部署完成后,才能进行程序运行时所需环境的搭建,比如lamp环境,最后再把项目放入环境中进行访问操作,整个过程稍显繁琐。对于docker来说,只需要安装完成,直接把项目和所需的环境封装在容器中。

​ 目标:简化部署流程,提供生产效率,使工作变得更加简单

2.docker ce: 社区版 免费
               ee:企业版 收费

四、Docker容器技术项目部署操作

1.验证:查看当前系统操作(centos7+)
cat   /etc/redhat-release
2.建议:更新系统的软件包;
yum -y update
3.重启:reboot
reboot
4.安装docker
yum -y install docker
5.查看docker版本信息
docker version
6.开启docker服务
systemctl start docker
7.设置docker开机自启动
systemctl enable docker
[root@VM-8-4-centos ~]# systemctl start docker
[root@VM-8-4-centos ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

8.docker工具安装完成后,就可以借助该工具提供的容器,来封装应应用程序和所需要的环境;

练习:docker容器封装LAMP环境,部署一个WEB端应用程序项目
LAMP环境:搭建动态网站

9.docker容器封装LAMP环境:一键部署

​ 9.1>可以先获取一个打包好(封装好)的lamp环境的镜像文件();

         docker  search  -s  下载量(数字)  lamp   #查找/搜索下载量排名靠前的lamp镜像;

​ 9.2>拉取(下载)合适的LAMP镜像文件到系统

         docker pull docker.io/tutum/lamp(镜像文件名字)
[root@VM-8-4-centos ~]# docker pull docker.io/tutum/lamp
Using default tag: latest
Trying to pull repository docker.io/tutum/lamp ... 
latest: Pulling from docker.io/tutum/lamp
8387d9ff0016: Pull complete 
3b52deaaf0ed: Pull complete 
4bd501fad6de: Pull complete 
a3ed95caeb02: Pull complete 
790f0e8363b9: Pull complete 
11f87572ad81: Pull complete 
341e06373981: Pull complete 
709079cecfb8: Pull complete 
55bf9bbb788a: Pull complete 
b41f3cfd3d47: Pull complete 
70789ae370c5: Pull complete 
43f2fd9a6779: Pull complete 
6a0b3a1558bd: Pull complete 
934438c9af31: Pull complete 
1cfba20318ab: Pull complete 
de7f3e54c21c: Pull complete 
596da16c3b16: Pull complete 
e94007c4319f: Pull complete 
3c013e645156: Pull complete 
Digest: sha256:d332e7e97606ac6407b0ba9ae9e9383c89d7e04c6f4853332e98f7d326408329
Status: Downloaded newer image for docker.io/tutum/lamp:latest

​ 9.3>查看镜像文件

         docker  images
[root@VM-8-4-centos ~]# docker  images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
docker.io/tutum/lamp   latest              3d49e175ec00        7 years ago         427 MB

​ 9.4>把LAMP环境运行在Docker容器(一键部署)

​ 1)在根目录下创建一个空白的文件夹(名字自定义):把LAMP镜像文件中关于mysql数据库的一些配置参数,映射到该目录下;

          mkdir /mysql_data
[root@VM-8-4-centos /]# ls /
bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  mysql_data  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

[root@VM-8-4-centos /]# ls -l
total 76
lrwxrwxrwx.   1 root root     7 Mar  7  2019 bin -> usr/bin
dr-xr-xr-x.   5 root root  4096 Oct 21 10:04 boot
drwxr-xr-x    2 root root  4096 Nov  5  2019 data
drwxr-xr-x   19 root root  2980 Oct 21 10:03 dev
drwxr-xr-x.  95 root root 12288 Oct 21 10:07 etc
drwxr-xr-x.   4 root root  4096 Feb 17  2023 home
lrwxrwxrwx.   1 root root     7 Mar  7  2019 lib -> usr/lib
lrwxrwxrwx.   1 root root     9 Mar  7  2019 lib64 -> usr/lib64
drwx------.   2 root root 16384 Mar  7  2019 lost+found
drwxr-xr-x.   2 root root  4096 Apr 11  2018 media
drwxr-xr-x.   2 root root  4096 Apr 11  2018 mnt
drwxr-xr-x    4  102 root  4096 Oct 21 12:04 mysql_data
drwxr-xr-x.   3 root root  4096 Mar  7  2019 opt
dr-xr-xr-x  151 root root     0 Oct 21 10:03 proc
dr-xr-x---.   7 root root  4096 Oct 21 13:38 root
drwxr-xr-x   32 root root  1060 Oct 21 12:03 run
lrwxrwxrwx.   1 root root     8 Mar  7  2019 sbin -> usr/sbin
drwxr-xr-x.   2 root root  4096 Apr 11  2018 srv
dr-xr-xr-x   13 root root     0 Oct 21 10:54 sys
drwxrwxrwt.  15 root root  4096 Oct 21 11:30 tmp
drwxr-xr-x.  13 root root  4096 Mar  7  2019 usr
drwxr-xr-x.  20 root root  4096 Oct 20 11:31 var

​ 2)运行LAMP环境到容器

          docker run -d --name=lamp(容器名字,自定义) -p 8080:80 -p 3306:3306 -v /mysql_data:/var/lib/mysql docker.io/tutum/lamp

扩展:端口号(port):每个软件都会有一个【唯一】的端口号,软件的名字是为了方便用户来识别,端口号,端口号是为了方便计算机系统和网络来识别;

[root@VM-8-4-centos ~]# docker run -d --name=lamp -p 8080:80 -p 3306:3306 -v /mysql_data:/var/lib/mysql docker.io/tutum/lamp
71d667ca9e90c7438962011906c7b2f442571261e349f90dbe4dec3557703358

删除容器:docker rm lamp(容器名字)

删除mysql配置参数文件夹:rm -rf /mysql_data

10.进入容器(还是以命令行的形式进行操作)

docker  exec -it  lamp(容器名字)       /bin/bash
[root@VM-8-4-centos ~]# docker exec  -it  lamp  /bin/bash
root@590c0db8921d:/# 

11.对mysql进行安全设置

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


root@590c0db8921d:/# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye

12.到此位置,已经在docker容器中把lamp环境全部封装,设置完毕,只剩下放入网站项目进行搭建即可(WEB端应用程序)

13.解压出chanzhieps系统项目的源文件包【www】,把项目的源文件包,上传到docke容器;

上传流程:源文件包—>本地系统—>云服务器centos系统---->docker容器lamp环境搞定+WEB网站项目? )

​ 1)源文件包上传到源服务器centos系统(上传到任意一个目录)

finalshell工具

​ 方式一:直接把软件包[拖拽]到对应的目录

​ 方式二:利用finalshell工具的上传功能

利用finalshell工具的上传功能

​ 2)上传完毕后,再从centos系统把源程序包放入docker容器:

    docker cp源程序包位置(/mnt/www或/home/www)   容器名字(lamp):/var/www/html
​   例: docker cp /mnt/wwwlamp:/var/www/html
​   注意: LAMP环境中项目源文件存放位置: var/www/html

​ 3)更改www源程序包的权限:

    chmod 777 www

源程序包的权限

14.来到云服务器控制台,开放项目的访问端口: 8080,80

​ 掌握:设置安全组规则

设置安全组规则

15.进行项目访问操作
http://云服务器公网的IP地址:8080/www/install.php
例:http://49.232.228.91:8080/www/install.php

进行项目访问操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咕咕在测试

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值