第10节 scratch构建runtime(linux)


❤️💕💕记录sealosopen in new window开源项目的学习过程。k8s,docker和云原生的学习open in new window。Myblog:http://nsddd.topopen in new window


[TOC]

开始

rootfs

wget -O rootfs.tar.xz https://ghproxy.com/https://github.com/debuerreotype/docker-debian-artifacts/raw/b024a792c752a5c6ccc422152ab0fd7197ae8860/jessie/rootfs.tar.xz

nginx

wget -O nginx.conf https://ghproxy.com/https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/nginx.conf

dockerfile

FROM scratch

# set the environment to honour SAP's proxy servers
ENV http_proxy http://sap:8080
ENV https_proxy http://sap:8080
ENV no_proxy .sap

# add and unpack an archive that contains a Debian root filesystem
ADD rootfs.tar.xz /

# use the apt-get package manager to install nginx and wget
RUN apt-get update && \
apt-get -y install nginx wget

# use wget to download a custom website into the image
RUN wget --no-check-certificate -O /usr/share/nginx/html/cheers.jpg https://ghproxy.com/https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/cheers.jpg && \
wget --no-check-certificate -O /usr/share/nginx/html/index.html https://ghproxy.com/https://github.diablo.corp/raw/slvi/docker-k8s-training/master/docker/res/cheers.html

# copy the custom nginx configuration into the image
COPY nginx.conf /etc/nginx/nginx.conf

# link nginx log files to Docker log collection facility
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log

# expose port 80 - the standard port for webservers
EXPOSE 80

# and make sure that nginx runs when a container is created
CMD ["nginx", "-g", "daemon off;"]

构建

docker build -t mylinux:1.0 .

效果

root@ubuntu:/c/rootfs-linux# docker run -it a53ceeb37a0b /bin/bash
root@74533e6a5638:/# ls
bin   dev  home  lib64	mnt  proc  run	 srv  tmp  var
boot  etc  lib	 media	opt  root  sbin  sys  usr

profile:

root@74533e6a5638:/bin# cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

dockerfile-ubuntu 构建方式

README

This repository contains Dockerfile of Ubuntuopen in new window for Dockeropen in new window's automated buildopen in new window published to the public Docker Hub Registryopen in new window.

Base Docker Image

Installation

  1. Install Dockeropen in new window.

  2. Download automated buildopen in new window from public Docker Hub Registryopen in new window: docker pull dockerfile/ubuntu

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/ubuntu" github.com/dockerfile/ubuntu)

Usage

docker run -it --rm dockerfile/ubuntu 

dockerfile

#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
#

# Pull base image.
FROM ubuntu:14.04

# Install.
RUN \
  sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
  apt-get update && \
  apt-get -y upgrade && \
  apt-get install -y build-essential && \
  apt-get install -y software-properties-common && \
  apt-get install -y byobu curl git htop man unzip vim wget && \
  rm -rf /var/lib/apt/lists/*

# Add files.
ADD root/.bashrc /root/.bashrc
ADD root/.gitconfig /root/.gitconfig
ADD root/.scripts /root/.scripts

# Set environment variables.
ENV HOME /root

# Define working directory.
WORKDIR /root

# Define default command.
CMD ["bash"]

user

注意

官网的构建方式往往最值得参考和学习,构建的语法也是非常good

pull

git clone https://ghproxy.com/https://github.com/dockerfile/ubuntu.git; cd ubuntu
docker build -t dockerfile/ubuntu:1.0 .

END 链接