Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

锋哥开始收Java学员啦!
当前位置: 主页 > Java文档 > Java基础相关 >

Docker学习与实践 PDF 下载


分享到:
时间:2020-04-05 15:31来源:http://www.java1234.com 作者:小锋  侵权举报
Docker学习与实践 PDF 下载
失效链接处理
Docker学习与实践  PDF  下载

 
本站整理下载:
提取码:gvcl 
 
 
相关截图:
 
主要内容:
一、docker的安装
1.依赖包安装
yum -y install yum-utils device-mapper-persistent-data lvm2
 
2.添加yum源
yum-config-manager --add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
#配置为安装最新版Docker CE
 
3.安装docker
yum -y install docker-ce
*官方为了简化安装流程提供了便捷的安装脚本
 
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun
 
4.启动docker
systemctl enable docker && systemctl start docker
 
5.建立docker用户和组
 
6.测试docker是否安装完成
[docker@dockertest ~]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/
For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
 
7.配置镜像加速器并重启服务
cat /etc/docker/daemon.json 
{
"registry-mirrors": [
"https://registry.docker-cn.com"
 ]
}
systemctl daemon-reload
systemctl restart docker
 
二、使用镜像
1.获取镜像
[root@dockertest ~]# docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
22dc81ace0ea: Pull complete 
1a8b3c87dba3: Pull complete 
91390a1c435a: Pull complete 
07844b14977e: Pull complete 
b78396653dae: Pull complete 
Digest: sha256:e348fbbea0e0a0e73ab0370de151e7800684445c509d46195aef73e090a49bd6
Status: Downloaded newer image for ubuntu:16.04
 
2.查看获取的镜像
[root@dockertest ~]# docker image ls 
#使用--help可以查看参数选项,比如自己定义显示的列
[root@dockertest ~]# docker image ls --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"
IMAGE ID            REPOSITORY          TAG
f975c5035748        ubuntu              16.04
f2a91732366c        hello-world         latest
 
#查看空间的占用
[root@dockertest ~]# docker system df
 
3.删除镜像
#删除本地镜像可以使用镜像短ID、长ID、镜像名或镜像摘要来删除
[root@dockertest ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              16.04               f975c5035748        7 days ago          112MB
centos              latest              2d194b392dd1        8 days ago          195MB
mysql               latest              5d4d51c57ea8        2 weeks ago         374MB
nginx               latest              e548f1a579cf        3 weeks ago         109MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
[root@dockertest ~]# docker image rm 5d4
[root@dockertest ~]# docker image rm nginx
[root@dockertest ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              16.04               f975c5035748        7 days ago          112MB
centos              latest              2d194b392dd1        8 days ago          195MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
#还可以使用docker image ls命令来配合
docker image rm $(docker image ls -q ubuntu)
docker image rm $(docker image ls -q -f before=centos)
 
三、容器的操作
1.容器的启动
①新建并启动
[root@dockertest ~]# docker run ubuntu:16.04 /bin/echo "hello world"
hello world
 
②启动一个bash终端,允许用户进行交互。
[root@dockertest ~]# docker run -ti ubuntu:16.04 /bin/bash
root@edf8af896cc0:/# pwd
/
#选项 '-t' 开启一个伪终端,'-i' 让容器的标准输入保持打开。
 
③后台运行
[root@dockertest ~]# docker run -d ubuntu:16.04 /bin/sh -c "while true; do echo hello world; sleep 10; done"
cab4112e91fb0d6eae3762ec2a07b13798e908503a8f58799ac50fd9b4aa7e37
#此时容器会在后台运行并不会把输出的结果打印到宿主机上面,可以使用docker logs查看输出信息。
[root@dockertest ~]# docker logs cab41
hello world
 
 
------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐