dockers学习笔记2--环境搭建

    我的电脑是win10,虽然现在win10开始也支持docker,但在linux机器会合适些,所以我先用VMware创建一个linux虚拟机--Centos7

安装虚拟机不多说,现在开始安装docker

1、删除docker(如果有的话)

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

2、安装一些系统必要的工具

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

3、获取docker的yum源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4、更新yum缓存

yum makecache fast

5、安装docker

yum -y install docker-ce

6、启动docker

systemctl start docker

配置daemon.json(可选)

[root@localhost ~]# vi /etc/docker/daemon.json
[root@localhost ~]# cat /etc/docker/daemon.json
{
  "graph": "/data/docker",     # docker工作目录
  "storage-driver": "overlay2",   # 存储驱动
  "insecure-registries": ["registry.access.redhat.com","quay.io"],  # 不安全的仓库
  "registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],  # 加速镜像
  "bip": "172.6.244.1/24",   # docker的网络,尽量要与宿主机有个对照关系
  "exec-opts": ["native.cgroupdriver=systemd"],  # cgroup的类型
  "live-restore": true  # 让docker容器不依懒docker引擎的死与活
}
[root@localhost ~]#

PS:上面注释信息去掉,不然启动时有报错

7、测试运行

docker run hello-world

 

8、由于是学习用,所以我还安装一些工具

yum install -y git vim gcc glibc-static telnet bridge-utils net-tools

 

9、查看本地拥有的image,hello world是第七步运行image时下载的。

[root@localhost ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        6 months ago        1.84kB
[root@localhost ~]# 

 

image说明如下,bootfs是内核,在上面有不同的base image,也就是各种发行版,Centos、Ubuntu、Debian等,在base image上可以安装软件(eg apache)构成新的image#2,在image#2上安装mysql可以构成新的image#4,

image#4 和image2可以共享相同的layer,也就是base image。

 

注册了Docker Hub账户后,可进行登录

[root@localhost ~]# docker login docker.io#登录docker仓库
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: bigni#输入账户密码
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded#登录成功
[root@localhost ~]# cat /root/.docker/config.json #登录信息放在这个文件下
{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "asdfbmk**********fdf=="
        }
    }
}[root@localhost ~]# echo "asdfbmk**********fdf==" | base64 -d #auth存放了账户信息,可用base64解密
bigni:123456
[root@localhost
~]#

 

posted @ 2019-07-06 10:48  爬行的龟  阅读(336)  评论(0编辑  收藏  举报
如有错误,欢迎指正 邮箱656521736@qq.com