前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >kubernetes(一)之Docker基础入门

kubernetes(一)之Docker基础入门

作者头像
alexhuiwang
发布2020-09-23 11:38:17
4910
发布2020-09-23 11:38:17
举报
文章被收录于专栏:运维博客

Docker入门

容器的定义

  • 运行在用户空间的独立进程
  • 与其他的用户空间程序是相互隔离
  • 一个容器运行在一个单独的用户空间
  • 底层是单独的内核空间

发展历史

  • FreeBSD jail, 2000
  • Linux VServer ,2001
    • CGroups
    • NameSpace
    • LXC
  • Docker ,2010
    • libcontainer
    • runC

docker容器编排三剑客

  • docker-mechine
  • docker-swarm
  • docker-compose

Linux NameSpace

  • 用于在一个抽象层上封装一个全局级别的可以进行切分的系统资源,主要如下的七个个级别的系统资源

NameSpaces

Constant

Isolates

Cgroup

CLONE_NEWCGROUP

Cgroup root directory,调派底层的cpu,内存,IO资源给容器

IPC

CLONE_NEIPC

System V IPC,POSIX message queues

NETWORK

COLNE_NENET

NetWork devices,stacks,ports,etc

Mount

ClONE_NEWNS

MountPoints

PID

COLNE_NEW_PID

Process PID

Users

COLNE_USER

User and Group IDs

UTS

CLONE_NEW_UTS

Hostname and NIS domain name

docker的版本

  • docker-ee
  • docker-ce

Docker的架构

kubernetes(一)之Docker基础入门
kubernetes(一)之Docker基础入门

docker的安装

  • 系统: centos7+
  • 初始化:配置主机名&ip略过
代码语言:javascript
复制
[root@centos7-node1 ~]# systemctl stop firewalld && systemctl disable firewalld
[root@centos7-node1 ~]# sed -i "s/SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config && reboot -f
[root@centos7-node1 ~]# yum install chrony wget curl git -y && systemctl enable chronyd && systemctl start chronyd && timedatectl set-timezone Asia/Shanghai && timedatectl set-ntp yes    #时间同步
[root@centos7-node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@centos7-node1 ~]# yum -y install epel-release
[root@centos7-node1 ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf  &&  sysctl -p
  • docker的安装和配置
代码语言:javascript
复制
# step 1: 安装必要的一些系统工具
 yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
yum makecache fast
yum -y install docker-ce

# 新增配置文件
 mkdir -p /etc/docker
 tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://0b8hhs68.mirror.aliyuncs.com"],
  "storage-driver": "overlay2",
  "graph":"/data/docker",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}
EOF
# 重载服务
sudo systemctl daemon-reload
sudo systemctl restart docker

docker 环境相关命令

代码语言:javascript
复制
docker info     #查看docker 信息
docker version   #查看版本信息

镜像相关命令

代码语言:javascript
复制
[root@centos7-node1 ~]# docker image -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker image COMMAND
Manage images
Commands:
  build Build an image from a Dockerfile
  history Show the history of an image
  import Import the contents from a tarball to create a filesystem image
  inspect Display detailed information on one or more images
  load Load an image from a tar archive or STDIN
  ls List images
  prune Remove unused images
  pull Pull an image or a repository from a registry
  push Push an image or a repository to a registry
  rm Remove one or more images
  save Save one or more images to a tar archive (streamed to STDOUT by default)
  tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

容器相关命令

代码语言:javascript
复制
[root@centos7-node1 ~]# docker container -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker container COMMAND
Manage containers
Commands:
  attach Attach local standard input, output, and error streams to a running container
  commit Create a new image from a container's changes
  cp Copy files/folders between a container and the local filesystem
  create Create a new container
  diff Inspect changes to files or directories on a container's filesystem
  exec Run a command in a running container
  export Export a container's filesystem as a tar archive
  inspect Display detailed information on one or more containers
  kill Kill one or more running containers
  logs Fetch the logs of a container
  ls List containers
  pause Pause all processes within one or more containers
  port List port mappings or a specific mapping for the container
  prune Remove all stopped containers
  rename Rename a container
  restart Restart one or more containers
  rm Remove one or more containers
  run Run a command in a new container
  start Start one or more stopped containers
  stats Display a live stream of container(s) resource usage statistics
  stop Stop one or more running containers
  top Display the running processes of a container
  unpause Unpause all processes within one or more containers
  update Update configuration of one or more containers
  wait Block until one or more containers stop, then print their exit codes
kubernetes(一)之Docker基础入门
kubernetes(一)之Docker基础入门

实践

镜像实践

代码语言:javascript
复制
[root@centos7-node1 ~]# docker search redis    #查找redis镜像
[root@centos7-node1 ~]# docker pull redis:4-alpine    #拖镜像
[root@centos7-node1 ~]# docker images    #查看所有镜像
[root@centos7-node1 ~]# docker inspect redis:4-alpine     #查看镜像详情
[root@centos7-node1 ~]# docker rmi redis:4-alpine           #删除镜像
[root@centos7-node1 ~]# docker image save redis:4-alpine -o redis.tar     #导出镜像
[root@centos7-node1 ~]# docker image load -i redis.tar         #导入镜像

登陆自己的阿里云容器镜像控制台,创建命名空间,然后在创建一个redis的本地镜像仓库

kubernetes(一)之Docker基础入门
kubernetes(一)之Docker基础入门

接下来就是比较常用的自己上传镜像到阿里云redis镜像仓库

代码语言:javascript
复制
[root@centos7-node1 ~]# docker login --username=valiente0822 registry.cn-hangzhou.aliyuncs.com   #登陆我的阿里云docker镜像仓库
[root@centos7-node1 ~]# docker image tag redis:4-alpine registry.cn-hangzhou.aliyuncs.com/myimgs/redis:4-alpine   #拷贝并修改tag
[root@centos7-node1 ~]# docker push registry.cn-hangzhou.aliyuncs.com/myimgs/redis:4-alpine    #上传镜像
[root@centos7-node1 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/myimgs/redis:4-alpine      #下载镜像

注意事项:

  • 创建的如果是阿里云私有仓库,pull镜像的时候需要docker login之后才能pull

容器实践

代码语言:javascript
复制
[root@centos7-node1 ~]# docker image pull centos:7   #拉取镜像
[root@centos7-node1 ~]# docker container run -it --name c1 centos:7 /bin/bash    #交互式运行容器
[root@centos7-node1 ~]# iptables -t nat -vnL    #新开终端,发现有nat iptables规则
[root@centos7-node1 ~]# docker ps -a             #查看运行或者停止状态的容器
[root@centos7-node1 ~]# docker start c1          #启动容器
[root@centos7-node1 ~]# docker ps                  #查看运行状态的容器
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Docker入门
    • 容器的定义
      • 发展历史
      • docker容器编排三剑客
      • Linux NameSpace
    • docker的版本
      • Docker的架构
        • docker的安装
          • docker 环境相关命令
          • 镜像相关命令
          • 容器相关命令
        • 实践
          • 镜像实践
          • 容器实践
      相关产品与服务
      容器服务
      腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档