# Docker-hub **Repository Path**: _sky/docker-hub ## Basic Information - **Project Name**: Docker-hub - **Description**: 🎉Docker 镜像加速。 支持多种仓库加速。 最新!最全!多种方法! docker镜像 - **Primary Language**: Docker - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 116 - **Created**: 2024-07-05 - **Last Updated**: 2024-07-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Docker Hub 镜像加速 国内拉取镜像有时会遇到困难,对于学习或者开发者来说很难受,此时可以配置镜像加速。 自建Docker镜像加速教程:[点我跳转。](https://gitee.com/wanfeng789/docker-hub/tree/master/%E8%87%AA%E5%BB%BADockr%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F/registry-mirror) 支持多种仓库,有不懂的欢迎在`Issue`区交流。 ### 安装Docker(如果安装困难可以使用手动安装) 官方安装脚本: ``` curl -fsSL https://get.docker.com | sh ``` 国内阿里云镜像 ``` curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun ```
手动安装Docker #### 下载 Docker: [文件下载地址—需要代理——下载后上传到服务器root目录](https://download.docker.com/linux/static/stable/x86_64/) ``` tar xzvf docker-26.1.3.tgz // 替换你的版本号 sudo mv docker/* /usr/local/bin/ ``` #### 创建 Docker 服务文件 ``` sudo vim /etc/systemd/system/docker.service ``` 添加以下内容 ``` [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify ExecStart=/usr/local/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process [Install] WantedBy=multi-user.target ``` #### 启动并启用 Docker 服务 ``` sudo systemctl daemon-reload sudo systemctl start docker sudo systemctl enable docker ``` #### 查看版本 ``` docker -v ```
安装Docker Compose 运行以下命令来下载 Docker Compose: ``` curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose ``` 添加可执行权限: ``` chmod +x /usr/local/bin/docker-compose ``` 验证安装: ``` docker-compose --version ``` --- 国内安装困难可以[手动下载文件](https://github.com/docker/compose/releases)上传到`/usr/local/bin`目录,并重命名为`docker-compose`,然后增加执行权限。 ---
## Docker常用命令: | 功能 | 命令 | 说明 | |-------------|-------------------|----------------| | 编译镜像 | `docker build -t 镜像名 .` | 先`docker login`登录docker hub | | 推送镜像 | `docker push 用户名/镜像名` | 需先标记镜像 `docker tag 65321f273e 用户名/镜像名` | | 查看容器 | `docker ps` | `-a`查看包括已停止的容器 | | 容器资源占用 | `docker stats` | 查看所有容器资源占用 | | 容器详细信息 | `docker inspect` | 挂载看`Mounts`网络看`Networks` | | 进入容器内部 | `docker exec -it 容器名 /bin/sh` | 结尾使用`/bash`也行 | | 创建容器网络 | `docker network create my-network` | `my-network`为网络名称 | | 容器加入网络 | `docker network connect my-network 容器名` | 替换容器名或ID | | 查看网络 | `docker network inspect my-network` | 查看`my-network`网络中的容器 | | 停止容器 | `docker stop` | `docker stop 容器名或ID` | | 启动容器 | `docker start` | `docker start 容器名或ID` | | 重启容器 | `docker restart` | `docker restart 容器名或ID` | | 删除容器 | `docker rm` | `docker rm 容器名或ID` | | 查看镜像 | `docker images` | `docker images 镜像名或ID` | | 删除镜像 | `docker rmi -f` | `docker rmi -f 镜像名或ID` | | 清除资源 | `docker system prune` | 清除所有未使用资源`容器 网络 镜像 缓存` | | 删除所有镜像 | `docker rmi -f $(docker images -aq)` | 删除所有镜像 | | 删除所有容器 | `docker container prune -f` | 删除所有已停止容器 | | 停止所有容器 | `docker stop $(docker ps -aq)` | 停止所有容器 | --- [官方仓库](https://hub.docker.com/) [官方文档](https://docs.docker.com/build/building/packaging/) --- ### vim编辑器 安装:`apt update`, `apt install curl wget git zip vim -y`或者`apk add vim` 常用命令: | 功能 | 命令 | 说明 | |-------------|-------------------|----------------| | 退出并保存 | `:wq` | 命令模式中执行 | | 只退出不保存 | `:q!` | 命令模式中执行 | | 清空所有内容 | `:%d` | 命令模式中执行 | | 粘贴时保持代码格式 | `:set paste` | 执行后按`i`进入编辑模式 | | 进入编辑模式 | `i` | 命令模式中执行 | | 退出编辑模式 | `esc` | 编辑模式中执行 | | 更改编码适配中文 | `:set encoding=utf-8` | 执行后按`i`进入编辑模式 | --- ## 配置加速地址 > Ubuntu 16.04+、Debian 8+、CentOS 7+ 创建或修改 `/etc/docker/daemon.json`: ``` sudo mkdir -p /etc/docker ``` ``` sudo tee /etc/docker/daemon.json < myimage.tar ``` #### 传送到B服务器 ``` scp myimage.tar root@192.0.2.0:/home ``` 然后输入B服务器root密码 #### B服务器加载Docker镜像 ``` cd /home ``` ``` docker load < myimage.tar ``` 查看镜像 ``` docker images ``` --- ## Docker Hub 镜像测速 拉取镜像时,可使用 `time` 统计所花费的总时间。测速前记得移除本地的镜像。 例如:`time docker pull node:latest` ## 卸载Docker ``` sudo systemctl stop docker sudo apt-get purge docker-ce docker-ce-cli containerd.io sudo rm -rf /etc/docker /var/lib/docker ``` --- ## Docker Hub 镜像加速列表 以下镜像站来源于互联网(感谢热心网友),可能出现宕机、转内网、关停等情况,建议同时配置多个镜像源。 #### 目前可用镜像加速 镜像 | 镜像加速地址 | 说明 | 其它加速 --- | --- | --- | --- [网友](https://do.nark.eu.org) | `https://do.nark.eu.org` | | Docker Hub [1panel](https://1panel.cn/docs/user_manual/containers/setting/) | `https://docker.1panel.live` | | Docker Hub [阿里云](https://cr.console.aliyun.com/) | `https://.mirror.aliyuncs.com` | 需登录 系统分配 | Docker Hub 未同步最新源镜像 ## 如果对您有帮助可以选择赞赏我 赞赏我