wittyResry / myIssue

My issue mark down^_^ 欢迎吐槽,讨论~~
https://github.com/wittyResry/myIssue/issues
The Unlicense
5 stars 1 forks source link

docker #78

Open wittyResry opened 6 years ago

wittyResry commented 6 years ago
wittyResry commented 6 years ago
一、环境准备(参考:https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository )
root@iZuf688z4yuz7afigdfnyxZ:~# lsb_release -a
LSB Version:    core-9.20160110ubuntu0.2-ia32:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-ia32:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial

root@iZuf688z4yuz7afigdfnyxZ:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo: unable to resolve host iZuf688z4yuz7afigdfnyxZ
OK
root@iZuf688z4yuz7afigdfnyxZ:~# sudo apt-key fingerprint 0EBFCD88
sudo: unable to resolve host iZuf688z4yuz7afigdfnyxZ
pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22
root@iZuf688z4yuz7afigdfnyxZ:~# vi /etc/hosts #添加下面一行
127.0.0.1       iZuf688z4yuz7afigdfnyxZ

# 本质上是对/etc/apt/source.list进行修改在最后加入我们编辑的内容以及系统自动生成的描述内容。
root@iZuf688z4yuz7afigdfnyxZ:~# echo $(lsb_release -cs)
xenial
root@iZuf688z4yuz7afigdfnyxZ:~# cat /etc/apt/sources.list
root@iZuf688z4yuz7afigdfnyxZ:~# sudo add-apt-repository \
>    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
>    $(lsb_release -cs) \
>    stable"
root@iZuf688z4yuz7afigdfnyxZ:~# cat /etc/apt/sources.list

deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable

# 再次更新包索引
$ sudo apt-get update

二、安装docker
wittyResry commented 1 year ago

➜ 0928 docker run -it alpine sh Unable to find image 'alpine:latest' locally latest: Pulling from library/alpine 213ec9aee27d: Pull complete Digest: sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad Status: Downloaded newer image for alpine:latest / # cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.16.2 PRETTY_NAME="Alpine Linux v3.16" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"

wittyResry commented 1 year ago

BusyBox简介

BusyBox很适合容器部署,恰巧因为它在设计时没有刻意考虑容器。BusyBox被其开发人员称为“嵌入式Linux的瑞士军刀”,它作为一个单一的小型可执行文件,包含一百多个最常用linux命令和工具的软件,他甚至还集成了一个http服务器和一个telnet服务器,而所有这一切功能却只有区区1M左右的大小。这也“迫使”它在容器技术出现之前,就可以开始采用类似容器的方法进行部署了。

BusyBox可以使用Linux或其他POSIX操作系统作为其基础进行部署,并将它们与许多常见的Linux实用程序捆绑在一起。如此一来,它成为了一个紧凑的单文件可执行文件,其中包含“完整”Linux发行版的许多功能——尽管这些完整版本中的不少其他功能选项,都以节省空间的名义,被从BusyBox中删除了。

alpine简介

Alpine Linux是一个轻型Linux发行版,它不同于通常的Linux发行版,Alpine采用了musl libc 和 BusyBox以减少系统的体积和运行时的资源消耗。Alpine Linux提供了自己的包管理工具:apk,我们可以通过https://pkgs.alpinelinux.org/packages 查询包信息。

BusyBox是因为是单一可执行文件而体积很小, 而Alpine Linux则是使用强化的内核,为其前身BusyBox的紧凑、简单的目标增加安全性。相较于BusyBox,Alpine Linux能让开发人员更容易添加功能。它的发行版基于BusyBox和musl库之上,因此在添加功能的方便性或结构紧凑度的这些维度上,Alpine Linux一枝独秀。

Docker官方也已开始推荐使用Alpine替代之前的Ubuntu来作为基础镜像,因为这样会带来多个好处,包括镜像下载速度加快,镜像安全性提高,占用更少的主机磁盘空间等。

Alpine Docker为了精简体积,默认是没有安装bash的。 需要的话可以查看官方文档:https://www.cyberciti.biz/faq/alpine-linux-install-bash-using-apk-command/

java基础镜像 docker.io/jeanblanchard/alpine-glibc nginx基础镜像 nginx:1.16.1-alpine

~ # cat /etc/os-release 
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.11.2
PRETTY_NAME="Alpine Linux v3.11"

~ # vi /etc/apk/repositories
# alpine系统默认数据源,下载较慢
http://dl-cdn.alpinelinux.org/alpine/v3.11/main
http://dl-cdn.alpinelinux.org/alpine/v3.11/community
# aliyun数据源(建议选这个)
https://mirrors.aliyun.com/alpine/v3.11/main/
https://mirrors.aliyun.com/alpine/v3.11/community/
# ustc数据源
https://mirrors.ustc.edu.cn/alpine/v3.11/main/
https://mirrors.ustc.edu.cn/alpine/v3.11/community/

安装telnet: Alpine镜像中的telnet在3.7版本后被转移至busybox-extras包中,需要使用apk单独安装。所以通过apk search telnet查找包再安装的方式已经不能用了
~ # apk add busybox-extras
安装scp
~ # apk add openssh-client
wittyResry commented 1 year ago

radhat或centos:查看文件 /etc/redhat-release

debian或ubuntu: 查看文件 /etc/debian_version

Slackware: 查看文件 /etc/slackware_version

ubuntu: 查看文件 /etc/lsb-release 或者 /etc/issue

wittyResry commented 1 year ago

Debian

使用镜像源
编辑/etc/apt/sources.list文件, 在文件最前面添加以下条目(操作前请做好相应备份)

cp /etc/apt/sources.list /etc/apt/sources.list.bak

cat << EOF > /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
EOF

apt-get update
apt-get -y install inetutils-ping telnet procps net-tools
镜像列表: http://www.debian.org/mirror/list

查看版本号
cat /etc/os-release

apt search ps
apt-get -y install procps [包含ps]
apt-get -y install net-tools [包含netstat ifconfig]
apt-get -y install inetutils-ping [ping]
apt-get -y install telnet

Ubuntu

修改 apt-get 源为国内镜像源的方法
cp /etc/apt/sources.list /etc/apt/sources.list.bak

cat << EOF > /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multivers
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
EOF

apt-get update