1

I'm creating minimalistic ubuntu os image for Azure and in the Docker file I'm trying to pull the tar and build it from scratch ( "FROM scratch.."). I see there are various tar available here and not sure which one should I be used - http://cloud-images.ubuntu.com/minimal/releases/bionic/release-20201210/. Need some advice on this.

Dev MK
  • 11
  • short answer : ubuntu-bionic-core-cloudimg-amd64-root.tar.gz – Koen Dec 15 '20 at 18:23
  • Depending how much from scratch you wanna go, you can go anywhere from using Ubuntu Base file system, add kernel, and go from there, or just use Azure provided image (on Azure). If you go down dirty you may want to look at this answer of mine, it's aimed at 20.xx but general steps can be adopted to 18.04 as well: https://askubuntu.com/a/1293305/1080682 I did not try 18.04 minimal images yet (and probably won't as I aim for 20.04 now), but seems any of files is mostly same, just packaged differently. – LuxZg Dec 15 '20 at 18:31

1 Answers1

1

according to https://ubuntu.com/blog/minimal-ubuntu-released

On Dockerhub, the new Ubuntu 18.04 LTS image is now the new Minimal Ubuntu 18.04 image. Launching a Docker instance with docker run ubuntu:18.04 therefore launches a Docker instance with the latest Minimal Ubuntu.

you can find the docker hub for ubuntu here : https://hub.docker.com/_/ubuntu

for 18.04 this is the dockerfile ubuntu uses to build the docker image (lcick on bionic in this page)

bionic dockerfile

https://github.com/tianon/docker-brew-ubuntu-core/blob/74249faf47098bef2cedad89696bfd1ed521e019/bionic/Dockerfile

i.e.

FROM scratch
ADD ubuntu-bionic-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

verify that the APT lists files do not exist

RUN [ -z "$(apt-get indextargets)" ]

(see https://bugs.launchpad.net/cloud-images/+bug/1699913)

make systemd-detect-virt return "docker"

See: https://github.com/systemd/systemd/blob/aa0c34279ee40bce2f9681b496922dedbadfca19/src/basic/virt.c#L434

RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container

CMD ["/bin/bash"]

Koen
  • 1,167
  • Thank you @Koen. – Dev MK Dec 17 '20 at 07:05
  • I built docker image but when I'm running it using docker run, I'm getting "Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory"\n". " This is my docker: `FROM scratch

    ADD http://cloud-images.ubuntu.com/minimal/releases/bionic/release-20201210/ubuntu-18.04-minimal-cloudimg-amd64-root.tar.xz /

    ENTRYPOINT ["/bin/sh", "/deploy/start.sh"]Please suggest what am I missing? To run the image:docker run -it --entrypoint /bin/sh `

    – Dev MK Dec 17 '20 at 12:51