Alpine Linux
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-2.27-r0.apk
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-bin-2.27-r0.apk
https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.27-r0/glibc-i18n-2.27-r0.apk
apk add --no-cache glibc-2.27-r0.apk
apk add --allow-untrusted glibc-2.27-r0.apk/usr/glibc-compat/bin/locale -a
/usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
/usr/glibc-compat/bin/localedef -i zh_CN -f UTF-8 zh_CN.UTF-8
export LANG=zh_CN.UTF-8
/usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG"
export LANG=
解决办法
哪个用户vi的时候输入中文乱码就在哪个用户主目录下编辑vimrc文件
比如:本例中root用户在vi的时候输入中文乱码
# vi .vimrc
#设置tab分隔符为4个空格
set tabstop=4
#解决中文乱码的设置
set termencoding=utf-8
set encoding=prc
保存立即生效
FROM base-alpine #这里写你的基础镜像 ENV LANG=C.UTF-8 # Here we install GNU libc (aka glibc) and set C.UTF-8 locale as default. RUN ALPINE_GLIBC_BASE_URL="https://github.com/sgerrand/alpine-pkg-glibc/releases/download" && \ ALPINE_GLIBC_PACKAGE_VERSION="2.27-r0" && \ ALPINE_GLIBC_BASE_PACKAGE_FILENAME="glibc-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \ ALPINE_GLIBC_BIN_PACKAGE_FILENAME="glibc-bin-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \ ALPINE_GLIBC_I18N_PACKAGE_FILENAME="glibc-i18n-$ALPINE_GLIBC_PACKAGE_VERSION.apk" && \ apk add --no-cache --virtual=.build-dependencies wget ca-certificates && \ echo \ "-----BEGIN PUBLIC KEY-----\ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZ2u1KJKUu/fW4A25y9m\ y70AGEa/J3Wi5ibNVGNn1gT1r0VfgeWd0pUybS4UmcHdiNzxJPgoWQhV2SSW1JYu\ tOqKZF5QSN6X937PTUpNBjUvLtTQ1ve1fp39uf/lEXPpFpOPL88LKnDBgbh7wkCp\ m2KzLVGChf83MS0ShL6G9EQIAUxLm99VpgRjwqTQ/KfzGtpke1wqws4au0Ab4qPY\ KXvMLSPLUp7cfulWvhmZSegr5AdhNw5KNizPqCJT8ZrGvgHypXyiFvvAH5YRtSsc\ Zvo9GI2e2MaZyo9/lvb+LbLEJZKEQckqRj4P26gmASrZEPStwc+yqy1ShHLA0j6m\ 1QIDAQAB\ -----END PUBLIC KEY-----" | sed 's/ */\n/g' > "/etc/apk/keys/sgerrand.rsa.pub" && \ wget \ "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_BASE_URL/$ALPINE_GLIBC_PACKAGE_VERSION/$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \ apk add --no-cache \ "$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_I18N_PACKAGE_FILENAME" && \ \ rm "/etc/apk/keys/sgerrand.rsa.pub" && \ /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true && \ echo "export LANG=$LANG" > /etc/profile.d/locale.sh && \ \ apk del glibc-i18n && \ \ rm "/root/.wget-hsts" && \ apk del .build-dependencies && \ rm \ "$ALPINE_GLIBC_BASE_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_BIN_PACKAGE_FILENAME" \ "$ALPINE_GLIBC_I18N_PACKAGE_FILENAME"
——————————————————————————————————
apk update
apk add busybox-extras
——————————————————————————————————
方法一 容器内部时区同步
# docker ps -a //查看registry镜像容器Id
CONTAINERID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc05bb235d29 registry:2 "/entrypoint.sh /etc/" 10 weeks ago Up 8 weeks 0.0.0.0:5000->5000/tcp registry-srv
# docker exec -it fc05bb235d29 /bin/sh //进入容器内部,alpine系统使用/bin/sh
~ # apk add --no-cache tzdata //安装时区相关包
~ # echo "Asiz/Shanghai" > /etc/timezone
~ # ln -sf /usr/share/zoneinfo/Asia/Shanghai/etc/localtime
~ # date
Mon Aug 28 15:45:37 CST 2017
———————————————————————————————————
alpine 更改时区
apk add --no-cache tzdata
echo "Asiz/Shanghai" > /etc/timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai/etc/localtime
date
Mon Aug 28 15:45:37 CST 2017
———————————————————————————————————
alpine 安装软件
/zookeeper-3.4.11 # cat /etc/apk/repositories
http://mirrors.ustc.edu.cn/alpine/v3.7/main
http://mirrors.ustc.edu.cn/alpine/v3.7/community
———————————————————————————————————
基础镜像升级
0 ls
1 vi /etc/apk/repositories
2 apk add gcc
3 apk update
4 apk add gcc
5 apk add musl
6 find / -name lib.musl*
7 exit
8 ls
9 cd /opt/
10 ls
11 cd jdk/
12 ls
13 apk add libgcc
14 find / -name libgcc_s.so.1
15 apk add apk add musl
16 apk add musl
17 find / -name libc.musl-x86_64.so.1
18 apk add font-sun-misc-1.0.3-r0
19 apk add font-sun-misc
20 apk add font-adobe-utopia-type1
21 apk add libxfont
22 history
———————————————————————————————————
网卡配置:
alpine01:~# more /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 125.39.193.170
netmask 255.255.255.128
gateway 125.39.193.129
auto eth1
#iface eth1 inet dhcp
iface eth1 inet manual
auto br0
#iface br0 inet static
iface br0 inet dhcp
bridge-ports eth1
bridge-stp 0
# address 10.10.254.222
# netmask 255.255.255.0
auto eth2
iface eth2 inet static
address 192.168.2.254
netmask 255.255.0.0
___________________________________________________________________
kernel.grsecurity.chroot_deny_chmod=0
kernel.grsecurity.chroot_deny_mknod=0
___________________________________________________________________
$ wget https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz; tar xzvf util-linux-2.24.tar.gz
$ cd util-linux-2.24
$ ./configure --without-ncurses && make nsenter
$ sudo cp nsenter /usr/local/bin
____________________________________________________________________
Installing Docker (Daemon) on Alpine Linux
2 Replies
I’m thinking about overhauling the infrastructure behind this site (and others) a bit and want to place as many services as possible into Docker containers that can then run inside a small Virtual Machine on Amazon EC2. So I started playing around with some Virtual Machines locally and since Ubuntu would be too boring, I decided to give Alpine Linux a try. It promises to be really lightweight so that seams ideal as a container host running inside a VM.
After finally figuring out how to install Alpine (which is another story), installing Docker was relatively straightforward based on their Wiki:
Add the Community Repository to the APK Repositories file:
~# vim /etc/apk/repositories
Add the following line:
http://dl-6.alpinelinux.org/alpine/edge/community
Or, if you are using a mirror, use the URL of the mirror, in my case:
http://mirror1.hs-esslingen.de/pub/Mirrors/alpine/edge/community
Update the list of available software:
~# apk update
Install Docker:
~# apk add docker
Configure docker daemon to start automatically on boot:
~# rc-update add docker boot
Start the docker daemon:
~# service docker start
Verify it’s running:
~# docker ps
Output should look like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Great, now I have a running Docker Daemon. Time to build a simple container. I quickly created a very short Dockerfile and ran docker build. After downloading some layers, it failed with a very cryptic error message:
failed to register layer: ApplyLayer exit status 1 stdout: stderr: chmod /bin/mount: permission denied
Searching for this message on Google lead me down many rabbit holes, but ultimately it takes only a single command to make it go away:
sysctl -w kernel.grsecurity.chroot_deny_chmod=0
This disables a security feature inside the Kernel, so it might not be safe for a production environment that runs containers but I think it’s acceptable for the machine that merely builds them.
_____________________________________________________________________
目录:
一、Alpine简要介绍
二、Alpine本地安装
三、Alpine在Docker下运行
四、Alpine的配置和使用
4.1网络相关文件
4.2更新国内源
4.3软件包管理工具apk的基本使用
4.4开启SSH服务
4.5安装nginx
一、Alpine简要介绍
Alpine 的意思是“高山的”,比如 Alpine plants高山植物,Alpine skiing高山滑雪、the alpine resort阿尔卑斯山胜地。
Alpine Linux 网站首页注明“Small!Simple!Secure!Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.”概括了以下特点:
1、小巧:基于Musl libc和busybox,和busybox一样小巧,最小的Docker镜像只有5MB;
2、安全:面向安全的轻量发行版;
3、简单:提供APK包管理工具,软件的搜索、安装、删除、升级都非常方便。
4、适合容器使用:由于小巧、功能完备,非常适合作为容器的基础镜像。
二、Alpine本地安装
Alpine Linux是一个完整的操作系统,像其他操作系统一样,可以将Alpine安装到本地硬盘中。我们可以创建一个VirtualBox虚拟机,在VirtualBox 下安装该系统,以便进行测试使用。具体安装过程,参见我写的另一篇文章《Alpine linux硬盘安装》,地址:http://blog.csdn.net/csdn_duomaomao/article/details/76053229。
主要是在安装过程中,指定一些电脑的基本设置,比如键盘布局、主机名、网卡、IP地址、root口令修改、时区设置、软件仓库地址、SSH服务器、NTP客户端、系统安装方式、磁盘格式化等。
三、Alpine在Docker下运行
1、Docker下的运行
官方 Alpine 镜像的文档:http://gliderlabs.viewdocs.io/docker-alpine/
可以使用Docker Toolbox,创建一台Docker虚拟主机,在该主机的Docker环境下运行alpine的 Docker容器。该容器就是一个Alpine Linux系统,
docker pull alpine
docker run -it --name myalpine alpine
2、作为Docker容器的基础镜像
以Alpine为基础镜像,创建一个MySQL容器,镜像大小只有36.5MB,
同样的方式使用Ubuntu系统作为基础镜像,镜像大小有184MB,
Dockerfile文件的内容:
FROM alpine:3.6
RUN apk add --no-cache mysql-client
ENTRYPOINT ["mysql"]
创建一个test/mysqlclient:1.0镜像
docker build -t test/mysqlclient:1.0 .
四、Alpine的配置和使用
4.1网络相关文件
#主机名文件
/etc/hostname
#使用新设置的主机名立刻生效,执行如下命令:
hostname -F /etc/hostname
#主机IP和域名映射文件
/etc/hosts
#文件内容为:
192.168.99.100 alpine.csdn.net
#DNS 服务器配置文件
/etc/resolv.conf
#文件内容为:
nameserver 218.2.135.1
nameserver 202.102.24.35
#网卡配置文件
/etc/network/interfaces
#文件内容为:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.3.166
netmask 255.255.255.0
gateway 192.168.3.254
#修改完相关配置以后,重新启动网络服务:
/etc/init.d/networking restart
网络相关的文档,详细参见:https://wiki.alpinelinux.org/wiki/Configure_Networking
4.2更新国内源
# Alpine的源文件为:
/etc/apk/repositories,
# 默认的源地址为:http://dl-cdn.alpinelinux.org/
#可以编辑源文件 /etc/apk/repositories,
#采用国内阿里云的源,文件内容为:
https://mirrors.aliyun.com/alpine/v3.6/main/https://mirrors.aliyun.com/alpine/v3.6/community/
# 如果采用中国科技大学的源,文件内容为:
https://mirrors.ustc.edu.cn/alpine/v3.6/main/https://mirrors.ustc.edu.cn/alpine/v3.6/community/
4.3软件包管理工具apk的基本使用
alpine 提供了非常好用的apk软件包管理工具,
可以方便地安装、删除、更新软件。
#查询openssh相关的软件包
apk search openssh
#安装一个软件包
apk add xxx
#删除已安装的xxx软件包
apk del xxx
#获取更多apk包管理的命令参数
apk --help
#比如安装常用的网络相关工具:
#更新软件包索引文件
apk update
#用于文本方式查看网页,用于测试http协议
apk add curl
#提供了查看网络连接的协议端口的命令ss,可以替代netstat命令
apk add iproute2
#drill 命令可以替代dig和nslookup DNS查询命令
apk add drill
#测试192.168.3.166的80端口,查看web服务是否能正常访问。
curl 192.168.3.166
#查看建立的TCP连接
ss -ta
#查询域名的信息
drill blog.csdn.net @8.8.8.8
#根据IP地址,反向查找域名
drill -x 8.8.8.8 @47.94.71.34
4.4开启SSH服务
#安装openssh-server服务器
apk add openssh-server
#修改配置文件 /etc/ssh/sshd_config,
#如果要想使用root用户远程管理,需要修改参数为:
PermitRootLogin yes
#将ssh服务配置为开机自动启动
rc-update add sshd
#如果你想立刻生效,可以执行命令:
/etc/init.d/sshd restart
4.5安装nginx
#安装Nginx软件并更新到最新,
apk add --update nginx
#手工启动Nginx
/etc/init.d/nginx
#将Nginx添加到启动服务中,下次开机自动运行
rc-update add nginx
#测试Nginx服务是否正常,使用curl访问,
#默认配置会返回nginx的404页面错误,标明服务已正常:
curl 192.168.3.166
myron