关于什么是Docker容器?我们该如何去简单化的将他理解?
我们为什么要使用docker?
对比传统虚拟机总结
特性 | 容器 | 虚拟机 |
---|---|---|
启动 | 秒级别 | 分钟级别 |
硬盘使用 | 一般为MB | 一般为GB |
性能 | 接近原生 | 弱于 |
系统支持量 | 单机支持上千个容器 | 一般几十个 |
安装需要的软件包,yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的yum install -y yum-utils device-mapper-persistent-data lvm2;
设置yum源;
安装docker ,出现输入的界面都按y;
查看docker版本,验证是否验证
1、yum install -y yum-utils device-mapper-persistent-data lvm2
2、yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
3、yum install -y docker-ce
4、docker --version
[root@coco ~]# sudo mkdir -p /etc/docker
[root@coco ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://nm61f549.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://nm61f549.mirror.aliyuncs.com"]
}
[root@coco ~]#
[root@coco ~]# sudo systemctl daemon-reload
[root@coco ~]# sudo systemctl restart docker
[root@coco ~]#
清空防火墙配置规则,然后再启动Docker
1、systemctl stop firwalld && systemctl disable firwalld
2、systemctl stop firewalld && systemctl disable firewalld
3、systemctl status firewalld.service
4、sudo systemctl daemon-reload
5、sudo systemctl start docker
6、sudo systemctl enable docker
7、docker version
1、centeos7
[root@coco ~]# docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
2、ubuntu安装
[root@coco ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
1、容器名一个为自己名字全拼
[root@coco ~]# docker run --name xiangzhenzeng -it centos:7
[root@d4b6dd2d653d /]# exit
exit
2、容器一个为首名字字母
[root@coco ~]# docker run --name xzz -it centos:7
[root@7f394dce45f8 /]#
[root@7f394dce45f8 /]# exit
exit
①docker start 容器名称 启动容器
②docker stop 容器名称 停止容器
③docker resart 容器名称 重启容器
[root@coco ~]# docker start xzz
xzz
[root@coco ~]# docker stop xzz
xzz
[root@coco ~]# docker restart xzz
xzz
①docker ps 查看正在运行的容器
②docker ps -a 查看全部容器
一、
[root@coco ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f394dce45f8 centos:7 "/bin/bash" 9 minutes ago Up 23 seconds xzz
二、
[root@coco ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f394dce45f8 centos:7 "/bin/bash" 10 minutes ago Up About a minute xzz
d4b6dd2d653d centos:7 "/bin/bash" 10 minutes ago Exited (0) 10 minutes ago xiangzhenzeng
1、第一种 exit
[root@coco ~]# docker run --name xzz -it centos:7
[root@e1e80097db9c /]# read escape sequence
[root@e1e80097db9c /]# exit
exit
2、 第二种 Ctrl+P+Q
[root@coco ~]# docker exec -it xzz /bin/bash
[root@e1e80097db9c /]#
[root@e1e80097db9c /]#
[root@e1e80097db9c /]#
[root@e1e80097db9c /]#
[root@e1e80097db9c /]# read escape sequence
[root@coco ~]#
[root@coco ~]# docker stop xzz
xzz
[root@coco ~]# docker exec -it xzz /bin/bash
Error response from daemon: Container e1e80097db9c0c0e82404b7eb0542017561381e8f863150b1abc42355d7ceae7 is not running
[root@coco ~]#
[root@coco ~]#
[root@coco ~]# docker start xzz
xzz
[root@coco ~]# docker exec -it xzz /bin/bash
[root@e1e80097db9c /]#
docker inspect 容器名称 查看容器或镜像的内部信息命令
[root@coco ~]# docker inspect xzz
docker images ls 查看所有镜像
[root@coco ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest ba6acccedd29 22 months ago 72.8MB
centos 7 eeb6ee3f44bd 23 months ago 204MB
centos latest 5d0da3dc9764 23 months ago 231MB
以上就是最基本的一些容器的入门命令了解操作,容器这个东西是真的很好用,小伙伴们抓紧学习起来吧!