k8s-pig-半小时学会Docker

上一篇 k8s-教程-构建生产级别Linux系统

清空你的杯子,方能再行注满,空无以求全。------ Bruce Lee

本篇介绍

本集内容

  1. 安装最新Dokcer
  2. 镜像操作
  3. 端口映射
  4. 目录挂载
  5. 日志查看
  6. 容器操作
  7. 网络相关

安装最新Dokcer

# 安装 Docker 官方源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 更新源
yum makecache fast
# 安装
yum install -y docker-ce

解决:
yum install -y yum-utils

然后在执行安装 Docker 官方源

# 安装 Docker 官方源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 更新源
yum makecache fast

# 安装
yum install docker-ce

# 设置开机自启
systemctl enable docker
# 启动
systemctl start docker
# 查看版本
docker version

镜像操作

https://hub.docker.com

## 1.下载镜像
docker pull nginx:1.17
# 查看本地已下载
docker images
# 删除镜像
docker rmi nginx:1.17

## 2.端口操作
# run 容器
docker run --name test-nginx -d -p 8080:80 nginx
# 主机网络
docker run --rm network host --name test-naginx2 nginx

## 3.挂载操作
# run 容器
docker run --name test-nginx2 -d -p 8081:80 -v /data:/usr/share/nginx/html nginx
# 进入
cd /data
# 添加文件
vi index.html 
# 在里面添加内容保存wq

## 4.日志操作
docker logs -f test-nginx

docker logs -f 容器ID

## 5. 进入容器里面,exit退出
# 进入容器
docker exec -it test-nginx sh

# 删除
docker rm test-nginx

# 遇到无法删除,先关闭再删除
docker stop test-nginx
docker rm -f test-nginx

# 查看容器详细信息
docker inspect test-nginx2

## 6.网络操作
# 查看容器详细信息
docker inspect test-nginx2

# 镜像busybox 工具
docker run -it --name test-nginx3 --link test-nginx busybox sh

# 上图
docker run -it --name test-nginx3 busybox sh

配套资料

请关注微信号(java-note),留言:K8S获取配套资料

下一篇 教你写Dockerfile并上传DockerHub统

发布了83 篇原创文章 · 获赞 24 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/u010638673/article/details/103519685
今日推荐