alpine基本使用

2018/12/31 alpine

启动一个alpine容器

awsome,only 4MB !!!

[root@localhost]# docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
alpine                           latest              9797e5e798a0        2 weeks ago         4.143 MB

Configure Networking 网络配置

Setting System Hostname 主机名/etc/hostname

echo "shortname" > /etc/hostname
立即生效
hostname -F /etc/hostname

/etc/hosts 文件

#Here's an IPv4 example:
192.168.1.150   shortname.domain.com

#And here's an IPv6 example:
2001:470:ffff:ff::2   shortname.domain.com

Configuring DNS DNS文件/etc/resolv.conf

/ # cat /etc/resolv.conf 
; generated by /sbin/dhclient-script
search localdomain
nameserver 192.168.110.2

##IPV6

2001:470:ffff:ff::2   shortname.domain.com

# For using a static IP and static nameservers, use one of the following examples.
nameserver 8.8.8.8
nameserver 8.8.4.4

开启IPV6

modprobe ipv6
echo "ipv6" >> /etc/modules

Interface Configuration 网卡配置 /etc/network/interfaces

本地回环 Loopback Configuration (Required)[Loopback配置必须在配置文件开头最先出现]

vi /etc/network/interfaces
auto lo
iface lo inet loopback

无线配置 Wireless Configuration

https://wiki.alpinelinux.org/wiki/Connecting_to_a_wireless_access_point

Ethernet Configuration 以太网配置,假设使用eth0设备


Initial Configuration

vim /etc/network/interfaces,添加如下行
auto eth0

IPv4 DHCP Configuration

iface eth0 inet dhcp

IPv4 Static Address Configuration

iface eth0 inet static
        address 192.168.1.150
        netmask 255.255.255.0
        gateway 192.168.1.1

IPv6 Stateless Autoconfiguration

iface eth0 inet6 manual
        pre-up echo 1 > /proc/sys/net/ipv6/conf/eth0/accept_ra

IPv6 Static Address Configuration

iface eth0 inet6 static
        address 2001:470:ffff:ff::2
        netmask 64
        gateway 2001:470:ffff:ff::1
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

demo

auto lo
iface lo inet loopback

auto eth0

iface eth0 inet static
        address 192.168.1.150
        netmask 255.255.255.0
        gateway 192.168.1.1

iface eth0 inet6 static
        address 2001:470:ffff:ff::2
        netmask 64
        gateway 2001:470:ffff:ff::1
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

防火墙 Firewalling with iptables and ip6tables

See also: Alpine Wallhttps://wiki.alpinelinux.org/wiki/Alpine_Wall - How-To Alpine Wallhttps://wiki.alpinelinux.org/wiki/How-To_Alpine_Wall - Alpine Wall User’s Guide https://wiki.alpinelinux.org/wiki/Alpine_Wall_User%27s_Guide

Install iptables/ip6tables

To install iptables:

apk add iptables

To install ip6tables:

apk add ip6tables

To install the man pages for iptables and ip6tables:

apk add iptables-doc
/ # apk add iptables
WARNING: Ignoring APKINDEX.70c88391.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.5022a8a2.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
  iptables (missing):
    required by: world[iptables]

===issue====
/ # apk update

Save Firewall Rules

开机启动
rc-update add iptables 

写入本地磁盘
/etc/init.d/iptables save

备份配置
lbu ci 

额外工具

apk add iproute2

更新国内源

apk默认的源为

/ # cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/v3.7/main
http://dl-cdn.alpinelinux.org/alpine/v3.7/community

可以编辑源文件 /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/

指定别名

http://nl.alpinelinux.org/alpine/v3.7/main
http://nl.alpinelinux.org/alpine/v3.7/community
@edge http://nl.alpinelinux.org/alpine/edge/main
@edgecommunity http://nl.alpinelinux.org/alpine/edge/community
@testing http://nl.alpinelinux.org/alpine/edge/testing

apk add stableapp newapp@edge bleedingapp@testing

包管理器 Alpine Linux package management

apk is the tool used to install, upgrade, or delete software on a running sytem. lbu is the tool used to capture the data necessary to restore a system to a previously configured state.

apk update 仓库更新到最新
apk upgrade
apk add openssh
apk add openssh openntp vim

安装本地apk包

apk add --allow-untrusted /path/to/file.apk
apk add --allow-untrusted /var/tig-2.2-r0.apk /var/git-2.11.1-20.apk

开启apk本地缓存

setup-apkcache

清除缓存

apk cache clean

apk -v cache clean

下载丢失的缓存

apk cache download

You can combine the two steps into one with the sync command - this cleans out old packages and downloads missing packages.

apk cache -v sync

Automatically Cleaning Cache on Reboot

/etc/local.d/*.stop file: /etc/local.d/cache.stop

#!/bin/sh


# verify the local cache on shutdown
apk cache -v sync

# We should always return 0
return 0

常用包安装

apk add iproute2 iptables iptables-doc openrc curl git openssh drill vim

Search

    Table of Contents