Depth study Docker + Jenkins dynamic deployment

Use a long Docker, this is the time to do sum up!

Common interview questions:

  1. How to modify the configuration file in Docker?

A, Docker Profile

Docker official website: https://docs.docker.com/

Docker Chinese Website: http://www.docker.org.cn/

1.1, Docker Profile

(1) What is the Docker

Docker is based on an open source container engine Go language implementation, application and Docker can be isolated from infrastructure layer, and is capable of the same basic settings as a program to manage the use of Docker can be packaged quickly, test, deploy applications.

(2) Docker comparison with the virtual machine

(3) Docker principle

 

The service pack mirrored images -> then to the Containers container (container is actually a virtual operating system inside out is also IP address) to run

1.2, Docker installation

There are two versions: Community Edition (CE), Enterprise Edition (EE, fees, use less)

Docker requirements CentOS system kernel version 3.10 or higher.

0、新建号虚拟机后,安装yum参考: https://jingyan.baidu.com/article/c35dbcb04764ae8916fcbc92.html
修改为固定IP: https://jingyan.baidu.com/article/c275f6ba6d1c87e33c75676e.html
1、通过 uname -r 命令查看当前的内核版本
uname -r
2、	使用 root 权限登录 Centos。确保 yum 包更新到最新。
yum -y update
3、	卸载旧版本(如果安装过旧版本的话)
yum remove docker docker-common docker-selinux docker-engine
4、	安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
yum install -y yum-utils device-mapper-persistent-data lvm2
5、	设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
6、	可以查看所有仓库中所有docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
7、	安装docker
sudo yum install -y docker-ce     #不指定版本默认安装的是最新稳定版
8、	启动并加入开机启动
systemctl start docker
systemctl enable docker
9、	验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
docker version

1.3, Docker some command

(1) commands mirroring

1、搜索镜像 # docker search java
可使用 docker search命令搜索存放在 Docker Hub(这是docker官方提供的存放所有docker镜像软件的地方,类似maven的中央仓库)中的镜像。执行该命令后, Docker就会在Docker Hub中搜索含有 java这个关键词的镜像仓库。
Docker Hub 官网https://hub.docker.com/search?q=java&type=image
2、下载镜像docker pull java:8
使用命令docker pull命令即可从 Docker Registry上下载镜像,执行该命令后,Docker会从 Docker Hub中的 java仓库下载最新版本的 Java镜像。如果要下载指定版本则在java后面加冒号指定版本
3、列出镜像使用 docker images命令即可列出已下载的镜像
4、删除镜像 使用 docker rmi java 命令即可删除指定镜像
docker rmi d23bdf5b1b1b

5、阿里镜像加速
详细参考: https://cr.console.aliyun.com/cn-hangzhou/mirrors

(2) container related commands

启动容器 docker run -d -p 81:80 nginx

在本例中,为 docker run添加了两个参数,含义如下:
-d 后台运行
-p 宿主机端口:容器端口     #开放容器端口到宿主机端口
访问 http://Docker宿主机 IP:81/,将会看到nginx的主界面如下:

需要注意的是,使用 docker run命令创建容器时,会先检查本地是否存在指定镜像。如果本地不存在该名称的镜像, Docker就会自动从 Docker Hub下载镜像并启动一个 Docker容器。

2. 列出容器用 docker ps命令即可列出运行中的容器
3. 查看容器的信息 docker inspect 3af5513d208e

(3) build your own docker mirror

1、将jar包上传linux服务器/usr/local/dockerapp目录,在jar包所在目录创建名为Dockerfile的文件
vi Dockerfile
2、在Dockerfile中添加以下内容

###指定java8环境镜像
FROM java:8
###复制文件到容器app-springboot
ADD docker-springboot-0.0.1.jar /app-springboot.jar
###声明启动端口号
EXPOSE 8080
###配置容器启动后执行的命令
ENTRYPOINT ["java","-jar","/app-springboot.jar"]

使用docker build命令构建镜像
docker build -t docker-springboot-0.0.1 .
# 格式: docker build -t 镜像名称:标签 Dockerfile的相对位置

docker run -p 8080:8080 docker-springboot-0.0.1 .

重启systemctl restart docker
关闭防火墙  systemctl stop firewalld


192.168.212.215:8080

1.4, some common software installation

How to install the software Docker modify the configuration file?

The answer: a container mounted external configuration file -v

Used way of mounting, the external profile cover profile inner container

(1) Nginx install

1.	下载Nginx镜像文件
docker pull nginx
docker images
2.	创建挂载目录
mkdir -p /data/nginx/{conf,conf.d,html,logs}
3.	编写Nginx配置文件
详细参考资料
4.	启动容器
docker run --name mynginx -d -p 80:80  -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx
6.查看容器
docker ps


通过Docker安装的Nginx如何配置nginx.conf
 Docker通过容器运行Nginx-----安装的目录 在容器中
/容器id/etc/nginx
/容器id/etc/mysql
默认情况下安装在 容器的etc目录

 

(2) MySQL Installation

1.查询mysql版本
docker search mysql
2.下载MySQL5.7版本
docker pull mysql:5.7  (这里选择的是第一个mysql镜像, :5.7选择的5.7版本)
3.等待下载完成、创建MySQL容器
docker create --name mysql3308 -e MYSQL_ROOT_PASSWORD=root -p 3308:3306 mysql:5.7
 创建容器名称为mysql3308,密码为root
5.	启动容器
docker start mysql3308
6.	进入到容器
docker exec -it mysql3308 bash
7.	mysql连接
mysql -uroot –p

1.5, how to modify the configuration file in Docker

(1) such as to modify nginx profile:

It is not recommended to change the profile on the inside of the container as described above.

(2) recommended by mounting modify the configuration file (also known as File Sync)

There is a face questions: how to modify the configuration file in Docker?

A: hanging off the vessel by an external profile covering the internal profile in the form of a container

 

Or Nginx Case:

docker run --name mynginx -d -p 80:80  -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx

说明:/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf

/data/nginx/conf/nginx.conf 指容器外的

:/etc/nginx/nginx.conf 指容器内的

作用是:容器外的配置文件覆盖容器内的配置文件

步骤:

a、创建挂载目录
mkdir -p /data/nginx/{conf,conf.d,html,logs}

cd /data/nginx

b、然后在外边copy一个外部nginx.conf的配置文件

上传放置在data/nginx/conf目录

 

二、Jenkins介绍

三、Docker+Jenkins动态部署

发布了52 篇原创文章 · 获赞 116 · 访问量 5万+

Guess you like

Origin blog.csdn.net/RuiKe1400360107/article/details/103938450