mirror of
https://github.com/yeasy/docker_practice.git
synced 2024-12-01 02:38:54 +00:00
143 lines
6.3 KiB
Markdown
143 lines
6.3 KiB
Markdown
|
## [Ubuntu](https://hub.docker.com/_/ubuntu/)
|
||
|
|
||
|
### 基本信息
|
||
|
[Ubuntu](https://en.wikipedia.org/wiki/Ubuntu) 是流行的 Linux 发行版,其自带软件版本往往较新一些。
|
||
|
|
||
|
该仓库位于 https://hub.docker.com/_/ubuntu/,提供了 Ubuntu 从 12.04 ~ 16.10 各个版本的镜像。
|
||
|
|
||
|
### 使用方法
|
||
|
默认会启动一个最小化的 Ubuntu 环境。
|
||
|
|
||
|
```
|
||
|
$ docker run --name some-ubuntu -i -t ubuntu
|
||
|
root@523c70904d54:/#
|
||
|
```
|
||
|
|
||
|
### Dockerfile
|
||
|
|
||
|
#### 12.04 版本
|
||
|
```
|
||
|
FROM scratch
|
||
|
ADD precise-core-amd64.tar.gz /
|
||
|
|
||
|
# a few minor docker-specific tweaks
|
||
|
# see https://github.com/dotcloud/docker/blob/master/contrib/mkimage/debootstrap
|
||
|
RUN echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||
|
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||
|
&& chmod +x /usr/sbin/policy-rc.d \
|
||
|
\
|
||
|
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||
|
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||
|
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||
|
\
|
||
|
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||
|
\
|
||
|
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
\
|
||
|
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||
|
\
|
||
|
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes
|
||
|
|
||
|
# delete all the apt list files since they're big and get stale quickly
|
||
|
RUN rm -rf /var/lib/apt/lists/*
|
||
|
# this forces "apt-get update" in dependent images, which is also good
|
||
|
|
||
|
# enable the universe
|
||
|
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||
|
|
||
|
# upgrade packages for now, since the tarballs aren't updated frequently enough
|
||
|
RUN apt-get update && apt-get dist-upgrade -y && rm -rf /var/lib/apt/lists/*
|
||
|
|
||
|
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||
|
CMD ["/bin/bash"]
|
||
|
```
|
||
|
|
||
|
#### 14.04 版本
|
||
|
```
|
||
|
FROM scratch
|
||
|
ADD trusty-core-amd64.tar.gz /
|
||
|
|
||
|
# a few minor docker-specific tweaks
|
||
|
# see https://github.com/dotcloud/docker/blob/master/contrib/mkimage/debootstrap
|
||
|
RUN echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||
|
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||
|
&& chmod +x /usr/sbin/policy-rc.d \
|
||
|
\
|
||
|
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||
|
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||
|
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||
|
\
|
||
|
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||
|
\
|
||
|
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
\
|
||
|
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||
|
\
|
||
|
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes
|
||
|
|
||
|
# delete all the apt list files since they're big and get stale quickly
|
||
|
RUN rm -rf /var/lib/apt/lists/*
|
||
|
# this forces "apt-get update" in dependent images, which is also good
|
||
|
|
||
|
# enable the universe
|
||
|
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||
|
|
||
|
# upgrade packages for now, since the tarballs aren't updated frequently enough
|
||
|
RUN apt-get update && apt-get dist-upgrade -y && rm -rf /var/lib/apt/lists/*
|
||
|
|
||
|
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||
|
CMD ["/bin/bash"]
|
||
|
```
|
||
|
|
||
|
#### 16.04 版本
|
||
|
|
||
|
```
|
||
|
FROM scratch
|
||
|
ADD ubuntu-xenial-core-cloudimg-amd64-root.tar.gz /
|
||
|
|
||
|
# a few minor docker-specific tweaks
|
||
|
# see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap
|
||
|
RUN set -xe \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L40-L48
|
||
|
&& echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
|
||
|
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
|
||
|
&& chmod +x /usr/sbin/policy-rc.d \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L54-L56
|
||
|
&& dpkg-divert --local --rename --add /sbin/initctl \
|
||
|
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
|
||
|
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L71-L78
|
||
|
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L85-L105
|
||
|
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L109-L115
|
||
|
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L118-L130
|
||
|
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
|
||
|
\
|
||
|
# https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap#L134-L151
|
||
|
&& echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
|
||
|
|
||
|
# delete all the apt list files since they're big and get stale quickly
|
||
|
RUN rm -rf /var/lib/apt/lists/*
|
||
|
# this forces "apt-get update" in dependent images, which is also good
|
||
|
|
||
|
# enable the universe
|
||
|
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
|
||
|
|
||
|
# overwrite this with 'CMD []' in a dependent Dockerfile
|
||
|
CMD ["/bin/bash"]
|
||
|
```
|