Docker基础

Docker基础

docker简介
1. docker可以理解为码头工人
2. docker - go语言开发
3. 快速交付软件,用完容器不要就删除,要就再重新启用一个
4. 保证程序运行环境一致性
5. 降低配置开发环境,生产环境的复杂度和成本
docker四大核心技术
1. IMAGE-镜像
2. CONTAINER-容器
3. DATA VOLUMES-数据卷
4. NETWORK-网络
5. http://www.docker.com
docker安装
```
yum install -y yum-utils device-mapper-persistent-data lvm2 - 安装前准备
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - 添加安装仓库
yum clean all
yum makecache fast
yum list docker-ce.x86_64  --showduplicates | sort -r --挑选需要安装的特定版本
yum install docker-ce-18.03.1.ce-1.el7.centos -y
systemctl start docker
docker run hello-world
docker version
推荐链接:
https://blog.csdn.net/shadow_zed/article/details/85557922
https://www.daocloud.io/mirror#accelerator-doc 获取docker安装加速代码
https://my.oschina.net/shyloveliyi/blog/1616025
https://www.lmaye.com/2019/04/28/20190428183357/
https://yeasy.gitbooks.io/docker_practice/install/centos.html
```
docker命令
```
systemctl start docker
systemctl status docker
systemctl stop docker
systemctl restart docker
```
搜索-获取-查看-镜像
```
docker search centos
docker pull centos
docker pull nginx
docker pull ubuntu
上述获取其中一个镜像位置:
[root@localhost ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
5667fdb72017: Pull complete
d83811f270d5: Pull complete
ee671aafb583: Pull complete
7fc152dfb3a6: Pull complete
Digest: sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
Status: Downloaded newer image for ubuntu:latest
[root@localhost ~]# ls /var/lib/docker/
builder     containers  network   plugins   swarm  trust
containerd  image       overlay2  runtimes  tmp    volumes
[root@localhost ~]#
[root@localhost overlay2]# pwd
/var/lib/docker/image/overlay2
[root@localhost overlay2]# ls
distribution  imagedb  layerdb  repositories.json
[root@localhost overlay2]# vim repositories.json
打开之后就看到了对应含有几个镜像

# 查看
docker images
docker images ubuntu
```
docker镜像重命名-删除
```
重命名
docker images
docker tag ubuntu:latest panda-ubuntus:v1.2
删除
docker rmi 2ca708c1c9cc 这样是删除不了的
docker rmi panda-ubuntus:v1.2 需要名称和版本号

```
docker镜像导出-导入
```
导出
[root@localhost ~]# docker save -o ubuntu.tar ubuntu
[root@localhost ~]# ls
anaconda-ks.cfg  ubuntu.tar
[root@localhost ~]# du -sh ubuntu.tar
64M     ubuntu.tar
[root@localhost ~]#
导入
[root@localhost ~]# docker rmi ubuntu:latest
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:b88f8848e9a1a4e4558ba7cfc4acc5879e1d0e7ac06401409062ad2627e6fb58
Deleted: sha256:2ca708c1c9ccc509b070f226d6e4712604e0c48b55d7d8f5adc9be4a4d36029a
Deleted: sha256:bd416bed302bc2f061a2f6848a565483a5f265932d2d4fa287ef511b7d1151c8
Deleted: sha256:5308e2e4a70bd4344383b8de54f8a52b62c41afb5caa16310326debd1499b748
Deleted: sha256:dab02287e04c8b8207210b90b4056bd865fcfab91469f39a1654075f550c5592
Deleted: sha256:a1aa3da2a80a775df55e880b094a1a8de19b919435ad0c71c29a0983d64e65db
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              f949e7d76d63        30 hours ago        126MB
hello-world         latest              fce289e99eb9        8 months ago        1.84kB
[root@localhost ~]# docker load < ubuntu.tar 或者 docker load --input ubuntu.tar
a1aa3da2a80a: Loading layer [==================================================>]  65.56MB/65.56MB
ef1a1ec5bba9: Loading layer [==================================================>]  991.2kB/991.2kB
6c3332381368: Loading layer [==================================================>]  15.87kB/15.87kB
e80c789bc6ac: Loading layer [==================================================>]  3.072kB/3.072kB
Loaded image: ubuntu:latest
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              f949e7d76d63        30 hours ago        126MB
ubuntu              latest              2ca708c1c9cc        7 days ago          64.2MB
hello-world         latest              fce289e99eb9        8 months ago        1.84kB
[root@localhost ~]#
```
docker镜像使用国内快速仓库
推荐是有这个网站:https://www.daocloud.io/mirror#accelerator-doc
上述网站提供的脚本会自动在/etc/docker目录下生成一个daemon.json的文件
也可以自己新建这个文件然后新建类似如下的信息:
{"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}
对应的新建脚本:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
docker镜像查看历史详细信息
```
历史信息
[root@localhost ~]# docker history ubuntu:latest
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
2ca708c1c9cc        7 days ago          /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
           7 days ago          /bin/sh -c mkdir -p /run/systemd && echo 'do…   7B
           7 days ago          /bin/sh -c set -xe   && echo '#!/bin/sh' > /…   745B
           7 days ago          /bin/sh -c [ -z "$(apt-get indextargets)" ]     987kB
           7 days ago          /bin/sh -c #(nop) ADD file:288ac0434f65264f3…   63.2MB
[root@localhost ~]#
镜像详细信息
docker inspect centos
根据模板创建镜像
下载模板地址:https://download.openvz.org/template/precreated
下载链接:https://download.openvz.org/template/precreated/ubuntu-12.04-x86.tar.gz
[root@localhost ~]# cat ubuntu-12.04-x86.tar.gz | docker import - ubuntu-mini-12.04
sha256:37bd25f26b7eeb0497d831e886a399d53a825c2966a9d4536b043ef4d6bdcc40
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu-mini-12.04   latest              37bd25f26b7e        9 seconds ago       322MB
nginx               latest              f949e7d76d63        31 hours ago        126MB
ubuntu              latest              2ca708c1c9cc        7 days ago          64.2MB
centos              latest              67fa590cfc1c        5 weeks ago         202MB
hello-world         latest              fce289e99eb9        8 months ago        1.84kB
opensuse/amd64      latest              c94c4a5730aa        19 months ago       108MB
[root@localhost ~]#
```

你可能感兴趣的:(Docker基础)