DOCKER(1):Docker高级应用课程学习过程和一些资源汇总

记录一下Docker高级应用课程学习过程和一些资源汇总

我的不同是在Ubuntu上进行

官网是最好的学习资源

主要参考:Install Docker Engine on Ubuntu | Docker Documentation 来安装

Docker — 从入门到实践 | Docker 从入门到实践

无意中发现一个连接工具 FinalShell  官方地址:http://www.hostbuf.com/


Prerequisites(前提)

OS requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Impish 21.10
  • Ubuntu Hirsute 21.04
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

Docker Engine is supported on x86_64 (or amd64), armhf, arm64, and s390x architectures.

Uninstall old versions(卸载旧版本)

Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

sudo apt-get remove docker docker-engine docker.io containerd runc

The contents of /var/lib/docker/(镜像、容器等的存储位置), including images, containers, volumes, and networks, are preserved.(仅删除软件,不删除已经创建的镜像和容器)

Uninstall Docker Engine(彻底删除)

Uninstall the Docker Engine, CLI, and Containerd packages:

 sudo apt-get purge docker-ce docker-ce-cli containerd.io

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

 sudo rm -rf /var/lib/docker

 sudo rm -rf /var/lib/containerd

delete any edited configuration files manually.(最后手动删除配置文件)


安装方法:

设置仓库安装(推荐)、DEB package手动安装、脚本安装

Set up the repository(设置仓库)

  • Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  • Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine(安装DOCKER引擎)

Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

sudo apt-get update

 sudo apt-get install docker-ce docker-ce-cli containerd.io

To install a specific version of Docker Engine, list the available versions in the repo, then select and install:(想要安装指定版本的docker)

a. List the versions available in your repo:

 apt-cache madison docker-ce

b. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

udo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

Verify that Docker Engine is installed correctly by running the hello-world image.(验证)

 sudo docker run hello-world

这个hello-world示例提供的信息还是比较有用的:其中提到了一个Docker daemon进程


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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Upgrade Docker Engine

To upgrade Docker Engine, first run sudo apt-get update


Manage Docker as a non-root user(不用sudo启动docker run)

To create the docker group and add your user:

 sudo groupadd docker
 sudo usermod -aG docker $USER

Log out and log back in so that your group membership is re-evaluated.

If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.

On a desktop Linux environment such as X Windows, log out of your session completely and then log back in.

On Linux, you can also run the following command to activate the changes to groups:

 newgrp docker 

Verify that you can run docker commands without sudo.

 docker run hello-world

If you initially ran Docker CLI commands using sudo (如果之前用了sudo启动docker,则会因为权限出错)before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/ directory was created with incorrect permissions due to the sudo commands.

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied

To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

 sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
 sudo chmod g+rwx "$HOME/.docker" -R

Docker配置阿里云镜像仓库:

仓库管理见:Docker 仓库管理_花纵酒的博客-CSDN博客

配置加速器:开新专题:Docker 安装_花纵酒的博客-CSDN博客

在/etc/docker目录下找到在daemon.json文件(没有就新建),将下面内容写入
 

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

推荐国内仓库地址:

https://registry.docker-cn.com

http://hub-mirror.c.163.com

https://3laho3y3.mirror.aliyuncs.com

http://f1361db2.m.daocloud.io

https://mirror.ccs.tencentyun.com
 

之后重新启动服务:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

执行 docker run hello-world的过程看如下图例:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值