docker笔记
docker镜像加速
阿里云容器服务
针对安装Docker for Mac的用户,您可以参考以下配置步骤:
在任务栏点击 Docker Desktop 应用图标,
Perferences,
在左侧导航菜单选择 Docker Engine,
在右侧输入栏编辑 json 文件。
将https://{签名}.mirror.aliyuncs.com加到"registry-mirrors"的数组里,
点击 Apply & Restart按钮,等待Docker重启并应用配置的镜像加速器。
查看配置是否成功
// Registry Mirrors:
docker info
其他镜像加速点
// Docker中国区官方镜像
https://registry.docker-cn.com
// 网易
http://hub-mirror.c.163.com
// ustc
https://docker.mirrors.ustc.edu.cn
// 中国科技大学
https://docker.mirrors.ustc.edu.cn
centos8环境配置
拉取centos8
// 拉取centos8镜像
docker pull centos:centos8
// 查看本地镜像
docker images | grep centos8
启动centos8
// 查看所有容器
docker ps -a
// 启动容器
docker start c1d29cf89bf4(容器id)
// 关闭容器
docker stop c1d29cf89bf4(容器id)
// 删除容器
docker rm c1d29cf89bf4(容器id)
// 查看镜像
docker images
// 倒序启动所有的容器命令,就不用特殊处理ip了
docker start $(docker ps -a | tail -n +2 | awk '{line[NR]=$1} END {i=NR; while(i>0) {print line[i]; i=i-1}}')
// 关闭所有的容器命令
docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2)
// 删除所有的容器命令
docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2)
// 删除所有的镜像
docker rmi $(docker images | awk '{print $3}' |tail -n +2)
参数 | 说明 |
---|---|
-d | 后台运行 |
-i | 交互模式 |
-t | 为容器重新分配一个伪输入终端 |
--privileged | 权限设置(access to all devices) |
--name | 容器别名 |
-p | 端口映射 宿主端口:容器端口 |
// 创建容器
docker run -dit -p 800:80 -p 1022:22 --privileged=true --name=centos8 centos:centos8 /usr/sbin/init
docker exec -it centos8 /bin/bash
查看容器id地址
// 查看容器IP地址,172.17.0.2
docker inspect centos8|grep "IPAddress"
容器生成镜像
// 停止容器
docker stop centos8
// 提交容器生成镜像
docker commit -m="添加php73" -a="Moments" centos8 centos8:php73
// 创建容器
docker run -dit -p 800:80 -p 1022:22 --privileged=true --name=centos8 centos8:php73 /usr/sbin/init
docker exec -it centos8 /bin/bash
// 停止容器
docker stop centos8
// 提交容器生成镜像
docker commit -m="添加nginx" -a="Moments" centos8 centos8:nginx
// 创建容器
docker run -dit -p 800:80 -p 1022:22 -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456 --privileged=true --name=centos8 centos8:nginx /usr/sbin/init
docker exec -it centos8 /bin/bash
// 停止容器
docker stop centos8
// 提交容器生成镜像
docker commit -m="添加mysql8" -a="Moments" centos8 centos8:mysql8
docker tag [镜像id] registry.cn-shenzhen.aliyuncs.com/[空间]/[镜像名]:[标签]
docker push registry.cn-shenzhen.aliyuncs.com/[空间]/[镜像名]:[标签]
windows安装
//
Docker Desktop Installer.exe
// 如果报错的话,更新ws可
wsl_update_x64.msi
centos安装
// 设置仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
// 安装docker
yum install docker-ce docker-ce-cli containerd.io
systemctl enable docker
systemctl status docker
systemctl start docker
// 拉取镜像包
docker pull centos:8.3.2011
// 生成实例
docker run -dit -p 800:80 -p 8443:443 -p 1022:22 -p 3316:3306 -e MYSQL\_ROOT\_PASSWORD=123456 --privileged=true --name=centos8 centos:8.3.2011 /usr/sbin/init
// 进入实例
docker exec -it centos8 /bin/bash