步骤1:准备一个服务器,并登录服务器
ssh root@ip
步骤2:卸载旧版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
步骤3:设置存储库
安装yum-utils
软件包(提供yum-config-manager
实用程序)并设置存储库
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
步骤4:安装Docker引擎
安装最新版本的Docker Engine、containerd和Docker Compose,或转到下一步安装特定版本:
$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
步骤5:启动docker
$ sudo systemctl start docker
步骤6:通过运行hello-world
映像来验证Docker引擎是否安装正确。
$ sudo docker run hello-world
#成功运行
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
步骤7:docker加速器配置,配置/etc/docker/daemon.json
# 添加 registry-mirrors
vim /etc/docker/daemon.json
# 内容
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
# 重载 docker 的配置文件
systemctl daemon-reload
# 重启 Docker
systemctl restart docker
步骤8:拉取jenkins,可以从这获取:Docker Hub
$ docker pull jenkins/jenkins:latest-jdk11
步骤9:运行jenkins并获取初始密码
# 运行方法1:
$ docker run -uroot -it -p 8080:8080 -p 50000:50000 -v $PWD/jenkins_home:/var/jenkins_home jenkins/jenkins:latest-jdk11
# 运行方法2:
$ docker run --name jenkins -d -p 8080:8080 -p 50000:50000 -v ${PWD}/jenkins:/var/jenkins_home jenkins/jenkins:latest-jdk11
# 查看默认密码:
$ docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
运行成功后:
步骤10:启动Jenkins
# 启动Jenkins
$ docker start jenkins
# 查看进程检查一下是否启动
$ docker ps -a
步骤11:查看日志
# 获取权限
$ chmod 777 jenkins
# 查看日志
$ docker logs -f jenkins
步骤12:需要开放对应的端口的配置 阿里云普通服务器在安全组中放开对应端口访问,轻量级在防火墙开放端口访问
步骤13:访问方式
本地启动的 Jenkins 访问 127.0.0.1:8080
云服务启动 Jenkins 访问 IP:8080
常用命令:
启动:systemctl start docker
重启:systemctl restart docker
开机自启动:systemctl enable docker
运行状态:systemctl status docker
运⾏容器:docker run -d --name=busybox busybox:latest ping 114.114.114.114
查看运⾏的容器:docker ps,docker ps -a
查看容器中运⾏的进程:docker top busybox
查看资源占⽤:docker stats busybox
容器:docker start/restart/stop/kill busybox
暂停容器:docker pause/unpause busybox
强制删除容器:docker rm -f busybox
查看所有镜像:docker images
查看关于jenkins的镜像:docker images | grep jenckins
搜索镜像:docker search busybox
拉取下载:docker pull busybox:latest
导出:docker save busybox > busybox.tar
导⼊:docker load < busybox.tar
删除:docker rmi busybox:latest
更改镜像名:docker tag busybox:latest busybox:test
查看镜像创建历史:docker history busybox
遇到的问题1:
ssh root@xxx
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:IQTvu7EDUhUaxd/HxrtMalYg3ku1BFJw+EkZO2N0IYM.
Please contact your system administrator.
Add correct host key in /Users/xx/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/xx/.ssh/known_hosts:3
ECDSA host key for 47.101.129.161 has changed and you have requested strict checking.
Host key verification failed.
解决1:
把本地的 /Users/xx/.ssh/known_hosts 这个文件的内容全部删除了 之后就可以了