docker安装详细教程(docker电脑如何安装)
安装docker
wget -O /etc/yum.repos.d/CentOS-Base.repo
yum -y install docker
systemctl start docker.service
systemctl enable docker.service
Docker基础命令
docker search//从Docker Hub搜索镜像
用法: docker search TERM
参数:
--automated=false 仅显示自动创建的镜像
--no-trunc=false 输出信息不截断显示
-s, --stars=0 指定仅显示评价为指定星级以上的镜像
docker search -s 500 nginx //搜索星级为500以上的镜像
[root@localhost ~]# docker info //查看当前信息
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 4
Server Version: 1.12.6
Storage Driver: devicemapper
Pool Name: docker-253:0-101174072-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 1.39 GB
Data Space Total: 107.4 GB
Data Space Available: 47.1 GB
Metadata Space Used: 2.945 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.145 GB
Thin Pool Minimum Free Space: 10.74 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
docker pull *** //下载镜像 网络需要好
docker pull docker.io/nginx
docker push *** // 上传镜像
docker push crushlinux/nginx//上传到crushlinux仓库
docker images //显示当前系统镜像
cat 本地容器快照名 | docker import - 自定义容器名:自定义标记名 //导入本地容器快照
[root@localhost ~]# ls
anaconda-ks.cfg centos.tar mysql5.tar nginx.tar tomcat.tar
[root@localhost ~]# cat centos.tar |docker import - centos:1
sha256:f4581438dc0c3261dd2396eeaa5b47fbc5d6df504ac9c0f91c9bba5159348009
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 1 f4581438dc0c 16 seconds ago 196.7 MB
docker run ***//运行一个容器,-i 交互式,-t 获得一个终端,-d 守护进程的形式运行
[root@localhost ~]# docker run -it centos:1 /bin/bash
[root@4ce4920e7c4f /]# exit
退出容器
1、 exit或ctrl+d //退出并停止容器
2、 先按Ctrl+p再按ctrl+q //退出伪终端,容器后台运行
docker ps //查看容器,-a 查看所有容器,-q只查看容器ID
docker rm //删除一个容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1ecd7068048 centos:1 "/bin/bash" 5 minutes ago Exited (0) About a minute ago sick_bhabha
359f023ec2fd centos:1 "/bin/bash -c 'while " 7 minutes ago Up 7 minutes boring_hypatia
4ce4920e7c4f centos:1 "/bin/bash" 8 minutes ago Exited (0) 7 minutes ago tender_spence
[root@localhost ~]# docker rm 4ce
4ce
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b1ecd7068048 centos:1 "/bin/bash" 5 minutes ago Exited (0) About a minute ago sick_bhabha
359f023ec2fd centos:1 "/bin/bash -c 'while " 7 minutes ago Up 7 minutes boring_hypatia
docker rmi //删除一个或多个镜像,-f强制删除
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 1 f4581438dc0c 10 minutes ago 196.7 MB
[root@localhost ~]# docker rmi centos:1
Failed to remove image (centos:1): Error response from daemon: conflict: unable to remove repository reference "centos:1" (must force) - container 359f023ec2
fd is using its referenced image f4581438dc0c
[root@localhost ~]# docker rmi -f centos:1
Untagged: centos:1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker create 创建一个容器,但不运行
docker create -it centos:1 /bin/bash
docker ps -a
docker start|stop|restart|kill //运行已停止的容器|停止|重启|杀死
docker save | load //存储镜像|载入镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 1 bdd1f8043fec 5 minutes ago 196.7 MB
[root@localhost ~]# docker save -o centos-6.5.tar centos:1
[root@localhost ~]# ls
anaconda-ks.cfg centos-6.5.tar centos.tar mysql5.tar nginx.tar tomcat.tar
端口映射
[root@localhost ~]# cat nginx.tar | docker import - nginx:1
sha256:bde88d3477d0fb797f76084b465533e15e98e0b39c6f1323667d46bfda317b26