docker基础安装及命令

docker官网:地址
阿里云镜像站:地址
镜像地址:https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
密钥:https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

配置yum

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim ali-docker.repo 
[aliyun.docker]
name=aliyun-docker-ce
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/
enabled=1
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

安装docker

[root@localhost ~]# yum -y install docker-ce

启动docker

[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# docker -v
Docker version 19.03.2, build 6a30dfc

docker加速

加速网址:               道客号               阿里云

1、道客号加速:

[root@localhost ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

2、阿里云加速:

[root@localhost ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://n8w27lqi.mirror.aliyuncs.com"]
}
EOF

加速源任选一个,修改完成重启docker:

[root@localhost ~]# systemctl restart docker.service
[root@localhost ~]# docker info		##查看docker详细信息
······
 Registry Mirrors:
  https://n8w27lqi.mirror.aliyuncs.com/
······

docker命令

1、拉取镜像

[root@localhost ~]# docker pull centos

2、搜索镜像

[root@localhost ~]# docker search ubuntu

3、查看本地镜像

[root@localhost ~]# docker images

4、删除本地镜像

[root@localhost ~]# docker rmi centos:latest

5、导出镜像

[root@localhost ~]# docker save -o centos.tar centos:latest

6、导入镜像

[root@localhost ~]# docker load --input centos.tar

7、镜像重命名

[root@localhost ~]# docker tag centos:latest hansir/centos-apache-php:V1.0.0

8、运行镜像

[root@localhost ~]# docker run centos /bin/echo hello world		##瞬时执行
[root@localhost ~]# docker run -it centos /bin/bash		##交互运行
[root@localhost ~]# docker run -itd --name test centos /bin/bash		##后端运行
进入容器:
	第一种:[root@localhost ~]# docker attach test		##exit退出会关闭容器,只有一个shell
	第二种:[root@localhost ~]# docker exec -it test /bin/bash		##exit退出不会关闭容器,进入新开一个shell,退出只会关闭新开的
exec在运行的容器中执行命令:
-d :分离模式: 在后台运行
-i :交互模式,即使没有附加也保持STDIN 打开
-t :分配一个伪终端

9、制作镜像

[root@localhost ~]#docker commit  container_name  mirror_name    制作镜像

10、容器命令

[root@localhost ~]# docker start test		##开启容器
[root@localhost ~]# docker stop test		##关闭容器
[root@localhost ~]# docker restart test		##重启容器
[root@localhost ~]# docker kill test		##快速关闭
[root@localhost ~]# docker pause test		##挂起
[root@localhost ~]# docker unpause test		##取消挂起
[root@localhost ~]# docker rm  id(name) 	##删除容器,可以删除多个,多接几个
[root@localhost ~]# docker rm  -f  id(name) ##强制删除
[root@localhost ~]# docker ps  				##查看正在运行的容器
[root@localhost ~]# docker ps -a   			##查看所有的容器,包括结束的

 

docker操作逻辑

docker基础安装及命令_第1张图片

你可能感兴趣的:(docker)