cat << EOF > 文件名
内容行1
内容行2
内容行3
EOF
-
Linux中使用cat EOF 将文本写入文件
-
让Linux用户sudo操作免密码
# vi /etc/sudoers
在最后面加一行
gex ALL=(ALL) NOPASSWD: NOPASSWD: ALL -
使用Dockerfile 创建自己的Docker镜像
1,一样是需要在 https://www.docker.com/ 上有自己的账号。
2,vi Dockerfile 里面如下写
FROM ubuntu:latestRUN apt update -y \
&& apt-get update \
&& apt install -y curl wget unzip jq \
&& curl -sL https://aka.ms/InstallAzureCLIDeb | bash \
&& wget -O – https://apt.releases.hashicorp.com/gpg | gpg –dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg \
&& echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main” | tee /etc/apt/sources.list.d/hashicorp.list \
&& apt update \
&& apt install terraform -y \
&& curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip” \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -rf awscliv2.zip \
&& apt upgrade -y3,在存在Dockerfile的目录下执行
docker build -t qinzhen/ubuntu-az-tf:latest . (注意,末尾的 . 非常重要不可或缺)
在过程中可以看到进度,比如apt的安装过程或者报错等4,之后就是docker push环节
-
自己构建一个Docker镜像
1,一样是需要在 https://www.docker.com/ 上有自己的账号
2,docker run -it ubuntu:latest 运行一个你需要的环境,也可以先pull下来再run
3,在环境里安装自己需要的组件,下面的例子是我安装了azure cli和terraform
docker run -it ubuntu:latest
apt update -y
apt upgrade -y
apt install -y curl wget sudo vim unzip
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
wget -O – https://apt.releases.hashicorp.com/gpg | sudo gpg –dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main” | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform -ycurl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”
unzip awscliv2.zip
sudo ./aws/install3,创建image:不要退出刚才的容器新连接一个ssh
docker commit -m “description” -a “author” <容器id> repository:tag“description”:描述信息。
“author”:作者名。
<容器id>:可以在就终端那里看到,形如root@2ce6712ef339:/#。可以看到<容器id>是2ce6712ef339。
reposiory:镜像仓库名,任取即可。
tag:镜像标签名,任取即可。
在本例中,生成镜像使用如下命令docker commit -m “ubuntu-az-terrafrom” -a “Zhen Qin” 6d726081f0fa qinzhen/ubuntu-az-tf:latest
4,将自建的Docker镜像推送至Docker Hub
docker push qinzhen/ubuntu-az-tf:latest -
Dockerhub上的镜像迁移到Harbor镜像仓库
1,到docker.io上注册账号。
2,找一台装了docker的linux机器执行docker login登录docker hub
下载镜像
docker pull teddysun/kms
打标签
docker tag teddysun/kms:latest qinzhen/kms:latest
推送
docker push qinzhen/kms:latest
之后Docker Hub里就可以看到
3,在harbor中创建–仓库管理
4,在harbor中创建–复制管理 (成功后点复制就可以下载所有之前打过标签的镜像)
-
Docker 中安装WordPress
-
Docker中安装Jenkins
使用以下方式可以在Jenkins中挂载企业CA,保证Jenkins的Git模块信任企业CA证书
docker run -d -p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /etc/localtime:/etc/localtime \
-v /etc/ssl/certs/:/etc/ssl/certs/ \ #企业CA放在这个目录中映射到容器内
–restart=on-failure jenkins/jenkins:lts-jdk21首次安装初始密码位置 cat /var/lib/docker/volumes/jenkins_home/_data/secrets/initialAdminPassword
-
AlmaLinux 安装官方源Docker
sudo dnf config-manager –add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
Dokcer 默认的映射卷位置 /var/lib/docker/volumes/
-
AlmaLinux 安装Nginx官方源主版本
vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true -
Docker命令清除无用镜像
1. 使用Docker命令清除无用镜像
#列出所有镜像 docker images #清理无用镜像 docker image prune -a
上述命令使用 Docker CLI 工具清除所有无用镜像。其中,“docker images”命令列出所有镜像,“docker image prune -a”命令清除所有无用镜像。
2. 使用Docker Compose清除无用镜像
当使用 Docker Compose 管理多个容器时,可以使用以下命令清除无用的镜像。
#列出所有镜像,包括未使用的镜像 docker-compose images --all #清除所有无用镜像 docker-compose image prune -a
停止、删除所有的docker容器和镜像
列出所有的容器 ID
docker ps -aq
停止所有的容器
docker stop $(docker ps -aq)
删除所有的容器
docker rm $(docker ps -aq)
删除所有的镜像
docker rmi $(docker images -q)
复制文件
docker cp mycontainer:/opt/file.txt /opt/local/
docker cp /opt/local/file.txt mycontainer:/opt/现在的docker有了专门清理资源(container、image、网络)的命令。 docker 1.13 中增加了
docker system prune
的命令,针对container、image可以使用docker container prune
、docker image prune
命令。docker image prune --force --all
或者docker image prune -f -a` : 删除所有不使用的镜像docker container prune -f
: 删除所有停止的容器