Linux容器-Docker的安装

  

如已安装先卸载旧版本

        Ubuntu
  
        查看已安装  dpkg -l | grep docker

walker@LAPTOP-IHP7E9GG:~$ dpkg -l | grep docker
ii  docker-ce                         5:20.10.2~3-0~ubuntu-focal        amd64        Docker: the open-source application container engine
ii  docker-ce-cli                     5:20.10.2~3-0~ubuntu-focal        amd64        Docker CLI: the open-source application container engine

  
        根据以上内容卸载  sudo apt-get autoremove

sudo apt-get autoremove docker-ce docker-ce-cli

  
        如果需要安装全新的docker,  需要删除缓存镜像,  网络,存储卷等文件

sudo rm -fr /var/lib/docker/

  

使用国内  daocloud  一键安装命令

  
        daocloud  一键安装

curl -sSL https://get.daocloud.io/docker | sh

  
        配置非  root  用户

根据提示使用

dockerd-rootless-setuptool.sh install

  
        启动  Docker

sudo service docker start

  
        Hello  world  docker run hello-world

walker@LAPTOP-IHP7E9GG:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
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.
 

  

配置国内docker镜像文件源

        编辑添加  vim /etc/docker/daemon.json  

 {
      "registry-mirrors": ["https://y0qd3iq.mirror.aliyuncs.com"]
 }

        重启docker服务  sudo service docker restart  

walker@LAPTOP-IHP7E9GG:~$ sudo service docker restart
 * Stopping Docker: docker [ OK ]
 * Starting Docker: docker

  
  

下载并启动  Ubuntu  镜像

  
        启动ubuntu,  若未安装,则会自动拉取最新  ubuntu  镜像文件  docker run -it ubuntu bash  

walker@LAPTOP-IHP7E9GG:~$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
da7391352a9b: Pull complete
14428a6d4bcd: Pull complete
2c2d948710f2: Pull complete
Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Status: Downloaded newer image for ubuntu:latest
root@88cb6518a6c8:/# ls
bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

  
  
参考资料:

  在  Linux上  安装  Docker