Docker——1.Docker安装部署

docker最核心的组件

  ·image镜像,构建容器(我们将应用程序运行所需的环境,打包为镜像)

  ·Container,容器(你的应用程序,就跑在容器中)

  ·镜像仓库(保存镜像文件,提供上传,下载镜像)作用好比GitHub

  ·Dockerfile 将你部署项目的操作,写成一个部署脚本,这就是dockerfile,且该脚本还能构建出镜像文件

 

创建容器的过程

  ·获取镜像,如docker pull centos ,从镜像仓库拉取

  ·使用镜像创建容器

  ·分配文件系统,挂载一个读写层,在读写层加载镜像

  ·分配网络/网桥接口,创建一个网络接口,让容器和宿主机通信

  ·容器获取ip地址

  ·执行容器命令,如/bin/bash

  ·反馈容器启动结果

 

安装docker

  docker最核心的组件

    ·image镜像, 构建容器(我们讲应用程序运行所需的环境,打包为镜像文件)

    ·Container,容器(你的应用程序,就跑在容器中),就是镜像的运行实例

    ·镜像仓库(dockerhub)(保存镜像文件,提供上传,下载镜像)作用好比github

    ·Dockerfile,将你部署鲜蘑菇的操作,写成一个部署脚本,这就是dockerfile,且该脚本还能够构建出镜像文件

 

  更新源

  wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

  wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

  更新yum缓存库

  yum clean all

  yum makecache

  配置主机

  iptables -F

  getenforce

  systemctl disable firewalld

  systemctl stop firewalld

  下载依赖

  yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop iftop iotop unzip sl psmisc nethogs glances bc ntpdate openldap-devel

  安装docker

  开启linux内核的流量转发

cat  <<EOF  >  /etc/sysctl.d/docker.conf

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

net.ipv4.conf.default.rp_filter = 0

net.ipv4.ip_forward=1

EOF

 

  modprobe br_netfilter

  sysctl -p /etc/sysctl.d/docker.conf

 

  配置yum仓库

  1.阿里云自带仓库 2.阿里云提供的dockers专属repo仓库

curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

curl -o /etc/yum.repos.d/Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo

 

  更新yum缓存

 

  mkdir -p /etc/docker

  touch /etc/docker/daemon.conf

  vim /etc/docker/daemon.conf 

{
"registry-mirrors" : [
"htttp://8xpk5wnt.mirror.aliyuncs.com"
]
}

systemctl daemon-reload

systemctl enable docker

systemctl restart docker

 

  查看docker是否正确启动

  docker version

 

  获取镜像,获取是从你配置好的docker镜像站中去拉去nginx镜像

  docker search nginx

  拉取下载镜像

  docker pull nginx

  查看本地docker镜像有什么

  docker image ls

  删除docker本地镜像

  docker rmi 镜像ID码

  运行镜像命令

  docker run 参数 镜像的名字/id    会返回容器id

  docker run -d -p 80:80 nginx   (-p 80:80的意思是端口映射,宿主机端口:容器端口,你访问宿主机的这个端口,也就访问到容器内的端口)

  查看容器是否在运行

  docker ps

 

  停止/开启容器运行

  docker stop id号

  docker start id号

  

posted @ 2023-02-07 17:56  真渡  阅读(129)  评论(0)    收藏  举报