赞
踩
目录
2)下载镜像使用的是pull从网络的镜像仓库拉取到本地docker中!
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
官方软件源默认启用了最新的软件
安装指定版本的docker-ce
# Step 1: 查找Docker-CE的版本:
yum list docker-ce.x86_64 --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: branch, fastestmirror, langpacks
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
sudo yum -y install docker-ce-[VERSION]
到 https://download.docker.com/linux/static/stable/x86_64/ 页面下载自己需要版本的发布包
1> 下载
[root@node3 ~]# wget -c https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz
2> 解压
[root@node3 ~]# tar -xf docker-20.10.17.tgz -C /usr/local/
3> 命令软连接
[root@node3 ~]# ln -sv /usr/local/docker/* /usr/bin/
4> 配置启动脚本
- [root@localhost ~]# vim /usr/lib/systemd/system/docker.service
- [Unit]
- Description=Docker Application Container Engine
- Documentation=https://docs.docker.com
- After=network-online.target firewalld.service
- Wants=network-online.target
- [Service]
- Type=notify
- ExecStart=/usr/bin/dockerd
- ExecReload=/bin/kill -s HUP $MAINPID
- LimitNOFILE=infinity
- LimitNPROC=infinity
- TimeoutStartSec=0
- Delegate=yes
- KillMode=process
- Restart=on-failure
- StartLimitBurst=3
- StartLimitInterval=60s
- [Install]
- WantedBy=multi-user.target
5> 创建docker组
[root@node3 ~]# groupadd -r docker
6> 启动服务
需要重新加载脚本然后启动
- [root@node3 ~]# systemctl daemon-reload
- [root@node3 ~]# systemctl start docker
- [root@node3 ~]# systemctl enable --now docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://9qawopss.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
- [root@node3 ~]# docker search ubuntu
- [root@node3 ~]# docker search centos
参数 | 说明 |
---|---|
NAME | 镜像名称 |
DESCRIPTION | 镜像说明 |
STARS | 点赞数量 |
OFFICIAL | 是否是官方的 |
AUTOMATED | 是否是自动构建的 |
- docker pull ubuntu:20.04
- docker pull centos:7
- [root@node3 docker]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- ubuntu 20.04 6df894023726 3 weeks ago 72.8MB
- centos 7 eeb6ee3f44bd 23 months ago 204MB
创建一个后台运行的容器 - 需要run选项:
- [root@node3 docker]# docker run -d --name ubuntu ubuntu:20.04
-
- -d 选项创建的容器后台运行 --name 容器名
创建容器并进入到容器内部:
- [root@node3 docker]# docker run -it --name centos7 centos:7 /bin/sh
- sh-4.2#
- -t 打开容器终端;-i 交互式访问;/bin/sh 进入容器必须要的解释器(shell)
用-it创建容器后,不停止容器退出:Ctrl+Q+P
- [root@node3 docker]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 334b759ef6d0 centos:7 "/bin/sh" 56 seconds ago Up 55 seconds centos7
- [root@node3 docker]# docker kill centos7
- centos7
- [root@node3 docker]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
用-it创建容器后,退出并停止容器:Ctrl+D 或 exit
- [root@node3 docker]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps 默认查看正在运行的容器:
- [root@node3 docker]# docker start centos7
- centos7
- [root@node3 docker]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 334b759ef6d0 centos:7 "/bin/sh" 9 minutes ago Up 3 seconds centos7
查看所有的容器-需要用到ps选项:
- [root@node3 docker]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 334b759ef6d0 centos:7 "/bin/sh" 10 minutes ago Up 42 seconds centos7
- 2992d992a21f centos:7 "/bin/bash" 23 minutes ago Exited (0) About a minute ago centos
- 50144503b9d3 ubuntu:20.04 "/bin/bash" 24 minutes ago Exited (0) 24 minutes ago ubuntu
#启动
docker start centos
#停止正在运行
docker stop centos
#stop 关闭运行的容器
#kill 杀死运行的容器
#重启
docker restart centos
这里我们需要使用到exec选项
- [root@node3 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 334b759ef6d0 centos:7 "/bin/sh" 18 minutes ago Up 4 minutes centos7
- [root@node3 ~]# docker exec -it centos7 /bin/sh
- sh-4.2#
需要inspect选项:
[root@node3 ~]# docker inspect centos:7
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。