一、Docker 简介
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。。
二、容器和虚拟机的区别
三个基本概念:
image(镜像)
Container(容器)
Reository(仓库)
三、安装 Docker
CentOS 7 安装 Docker官网指导
https://docs.docker.com/engine/install/centos/
3.1、卸载掉旧版本的 Docker
yum remove -y docker docker-client docker-client-latest docker-common \ docker-latest docker-latest-logrotate docker-logrotate \ docker-selinux docker-engine-selinux docker-engine
3.2、执行以下安装命令去安装依赖包
yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo [root@centos7 ~] yum -y install docker-ce docker-ce-cli containerd.io [root@centos7 ~]# docker ps --查看docker Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? --docker没有启动
3.3、启动 Docker
[root@centos7 ~]#systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@centos7 ~]#systemctl start docker [root@centos7 ~]#systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2021-01-16 18:47:43 EST; 6s ago Docs: https://docs.docker.com Main PID: 2435 (dockerd) Memory: 45.1M CGroup: /system.slice/docker.service └─2435 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.051980834-05:00" level=info msg="ccResolverWrapper: ...e=grpc Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.051989827-05:00" level=info msg="ClientConn switchin...e=grpc Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.077331225-05:00" level=info msg="Loading containers: start." Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.382655173-05:00" level=info msg="Default bridge (doc...dress" Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.449861379-05:00" level=info msg="Loading containers: done." Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.463137686-05:00" level=warning msg="Not using native...erlay2 Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.463311349-05:00" level=info msg="Docker daemon" comm...0.10.2 Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.463380194-05:00" level=info msg="Daemon has complete...ation" Jan 16 18:47:43 centos7 systemd[1]: Started Docker Application Container Engine. Jan 16 18:47:43 centos7 dockerd[2435]: time="2021-01-16T18:47:43.493313812-05:00" level=info msg="API listen on /var/....sock" Hint: Some lines were ellipsized, use -l to show in full. [root@centos7 ~]# docker ps --查看容器 [root@centos7 ~]# docker version --查看版本 [root@centos7 ~]# docker info --查看版本
3.4.修改 Docker 本地存储位置的方法
默认情况下 Docker的存放位置为:/var/lib/docker 可以通过命令查看具体位置:docker info | grep "Docker Root Dir" 方法一:修改到其它目录 首先停掉 Docker 服务: systemctl stop docker 然后移动整个/var/lib/docker 目录到目的路径 mkdir -p /root/data/docker mv /var/lib/docker /root/data/docker ln -s /root/data/docker /var/lib/docker --快捷方式
三、Docker命令
国内镜像:https://hub.daocloud.io/ docker pull daocloud.io/library/centos:8.2.2004 创建容器 #从网络拉取镜像 docker pull centos:7.8.2003 # 创建一个容器,包括了 CentOS 7.8 运行的一些基础环境 #docker images --镜像 REPOSITORY TAG IMAGE ID CREATED SIZE daocloud.io/library/centos 8.2.2004 831691599b88 7 months ago 215MB centos 7.8.2003 afb6fca791e0 8 months ago 203MB docker run -d --name centos7.8 -h centos7.8 \ -p 220:22 -p 3387:3389 \ --privileged=true \ centos:7.8.2003 /usr/sbin/init # 进入容器 docker exec -it centos7.8 bash