Installing Docker on Debian image ends up with a huge image - docker

I'm baking a Debian Docker image with Docker installed. When I follow the official instructions on installing Docker on Debian I end up with an 871MB size image. The official Docker image (built on Alpine) is closer to around 60-70MB. I don't understand why using Debian would need hundreds of additional MB.
Any ideas on how I can reduce the image size? Below is my Dockerfile.
FROM debian:buster-slim
RUN apt-get update \
&& apt-get install -y \
curl \
gnupg-agent \
software-properties-common \
lsb-release \
&& curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce docker-ce-cli containerd.io \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Related

Running headless Chrome with webgl and Nvidia GPU inside a container

I'm trying to run headless chrome inside a docker container with the webgl support and the hardware acceleration.
I have a Nvidia graphic card and if I test of the drivers with the command suggested by Nvidia, it is successful
docker run --gpus all nvidia/opengl:base nvidia-smi
This is my dockerfile :
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu18.04
# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ca-certificates \
build-essential \
g++ \
libxinerama-dev \
libxext-dev \
libxrandr-dev \
libxi-dev \
libxcursor-dev \
libxxf86vm-dev \
libvulkan-dev && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
RUN apt-get update \
&& apt-get install -y wget gnupg ca-certificates \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
# We install Chrome to get all the OS level dependencies, but Chrome itself
# is not actually used as it's packaged in the node puppeteer library.
# Alternatively, we could could include the entire dep list ourselves
# (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
# but that seems too easy to get out of date.
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/* \
&& wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
&& chmod +x /usr/sbin/wait-for-it.sh
# Install GTK, pulseaudio and fonts
RUN apt-get update && \
apt-get -y --no-install-recommends install ca-certificates tzdata \
libcanberra-gtk-module libexif12 pulseaudio attr \
fonts-dejavu-core fonts-freefont-ttf fonts-guru-extra \
fonts-kacst fonts-kacst-one fonts-khmeros-core fonts-lao \
fonts-liberation fonts-lklug-sinhala fonts-lohit-guru \
fonts-nanum fonts-opensymbol fonts-sil-abyssinica \
fonts-sil-padauk fonts-symbola fonts-takao-pgothic \
fonts-tibetan-machine fonts-tlwg-garuda-ttf \
fonts-tlwg-kinnari-ttf fonts-tlwg-laksaman-ttf \
fonts-tlwg-loma-ttf fonts-tlwg-mono-ttf \
fonts-tlwg-norasi-ttf fonts-tlwg-purisa-ttf \
fonts-tlwg-sawasdee-ttf fonts-tlwg-typewriter-ttf \
fonts-tlwg-typist-ttf fonts-tlwg-typo-ttf \
fonts-tlwg-umpush-ttf fonts-tlwg-waree-ttf \
ttf-bitstream-vera ttf-dejavu-core ttf-ubuntu-font-family \
fonts-arphic-ukai fonts-arphic-uming \
fonts-ipafont-mincho fonts-ipafont-gothic \
fonts-unfonts-core && \
rm -rf -- /var/lib/apt/lists /tmp/*.deb
however when I run the container with :
docker run -it --gpus all mytest
and I try to capture a screenshot inside the container with:
google-chrome --no-sandbox --headless --screenshot=ss.png chrome://gpu/
I get the error : Segmentation fault (core dumped)
Any idea ?
GPU chome headless options are still problematic, especially when You try that in containers. Just update image to current nvidia/opengl:1.2-glvnd-runtime-ubuntu20.04 and You will get output without any memory dump. I had same issues about year ago on some chrome options with vulkan support (now same thing works ok).

apt-get error: Version '5:19.03.4~3-0~ubuntu-bionic' for 'docker-ce' was not found

Documentation
provides syntax to install specific version of docker-ce:
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
On similar line, below dockerfile uses the above syntax:
FROM jenkins/jenkins:lts
ENV DEBIAN_FRONTEND=noninteractive
USER root
ARG DOCKER_GID=497
# Create Docker Group with GID
# Set default value of 497 if DOCKER_GID set to blank string by Docker compose
RUN groupadd -g ${DOCKER_GID:-497} docker
# Install base packages for docker, docker-compose & ansible
# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 && \
RUN apt-get update -y && \
apt-get -y install bc \
gawk \
libffi-dev \
musl-dev \
apt-transport-https \
curl \
python3 \
python3-dev \
python3-setuptools \
gcc \
make \
libssl-dev \
python3-pip
# Used at build time but not runtime
ARG DOCKER_VERSION=5:19.03.4~3-0~ubuntu-bionic
# Install the latest Docker CE binaries and add user `jenkins` to the docker group
RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
usermod -aG docker jenkins
ARG DOCKER_COMPOSE=1.24.1
# Install docker compose
RUN curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE:-1.24.1}/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
RUN pip3 install ansible boto3
# Change to jenkins user
USER jenkins
# Add jenkins plugin
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
fails at line below(on build):
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
where default values are retrieved from command: apt-cache madison docker-ce | awk 'NR==1{print $3}' in my local docker host
where docker-compose build gives below error:
Reading state information...
E: Version '5:19.03.4~3-0~ubuntu-bionic' for 'docker-ce' was not found
E: Version '5:19.03.4~3-0~ubuntu-bionic' for 'docker-ce-cli' was not found
ERROR: Service 'jenkins' failed to build: The command '/bin/sh -c apt-get update && apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common && curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" && apt-get update && apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} containerd.io && usermod -aG docker jenkins' returned a non-zero code: 100
apt-get -y install docker-ce docker-ce-cli containerd.io is able to download and install the latest version of ubuntu packages, but why download and install of specific version of ubuntu package fails?
apt-get -y install docker-ce=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
docker-ce-cli=${DOCKER_VERSION:-5:19.03.4~3-0~ubuntu-bionic} \
containerd.io && \
You've selected Docker versions based on what's available on your build host, not what's available inside the container image you're building. The jenkins:lts image is based on Debian Stretch, not Ubuntu Bionic.
Dockerfiles are actually just running fairly ordinary Docker operations. So, for example, you can run docker run -ti -u root jenkins/jenkins:lts /bin/bash, run your RUN scripts by hand, and check the apt-cache output inside the container:
# apt-cache madison docker-ce
docker-ce | 5:19.03.4~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.3~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.2~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
docker-ce | 5:19.03.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
Also, a failed docker build should leave the partially-complete image around; so you can use that directly to investigate a failure. As an example with a trivially failing step RUN false:
⋮
Removing intermediate container baaeab34bb8c
---> 6d34bab07796
Step 3/3 : RUN false
---> Running in 8347f442dfaa
The command '/bin/sh -c false' returned a non-zero code: 1
The 6d34bab07796 image is left around. You can pass that to docker run and investigate why the command failed. The 8347f442dfaa container is also left around, though exited; you can use the various docker container subcommands to investigate it as well.

can not install docker in Ubuntu 16.04

I have installed ubuntu minimal in my virtual box (Ubuntu 16.04 LTS "Xenial Xerus")
I tried to install docker as follow:
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && apt-key fingerprint 0EBFCD88
dpkg -S add-apt-repository && add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -
s)-$(uname -m)" -o /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
but I have an error in this line
apt-get install -y docker-ce docker-ce-cli containerd.io
the error is:
I think you use the older docker commands for Ubuntu.
Try this:
If you have Docker already installed with apt-get - uninstall it.
sudo apt remove docker docker-engine docker.io
You need additional packages to allow apt use HTTP repositories. You can have them installed already, but run following to make it clear.
sudo apt install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
next
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add docker repository to your /etc/apt/source.list
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
next
sudo apt update
and finally
sudo apt install docker-ce

Docker in docker on Windows 10

I have a Ubuntu18.04 server and want to run docker in it to launch containers.
Because I have Windows locally, I planned to use Docker to launch the Ubuntu18.04 server itself. But there seems to be some problem with runlevels on Windows:
invoke-rc.d: could not determine current runlevel
This problem is already known, but without any answer yet.
I tried the following Dockerfile:
FROM ubuntu:18.04
ARG WORK_DIR="myapp"
WORKDIR ${WORK_DIR}
# some basic programs
RUN apt update && apt install -y \
zsh \
wget \
curl \
git-core \
vim \
emacs
#install docker
# https://answers.microsoft.com/en-us/windows/forum/windows_10-windows_install/errors-in-ubuntu-1804-on-windows-10/fe349f3d-3d58-4d90-9f8f-c14d7c12af8b
RUN cp -p /bin/true /sbin/ebtables \
&& apt update -y \
&& apt upgrade -y \
apt update \
&& apt install -y apt-transport-https ca-certificates curl software-properties-common \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" \
&& apt update \
&& apt-cache policy docker-ce \
&& echo exit 0 > /usr/sbin/policy-rc.d \
&& export RUNLEVEL=1 && apt install -y docker-ce
RUN docker run hello-world
The apt install -y docker-ce raises the error.

Docker Image with Lando Support

I am trying to build a Docker image where Lando should be preinstalled.
My Dockerfile looks like :
FROM devwithlando/php:7.1-fpm
RUN apt-get update -y \
&& docker-php-ext-install pcntl
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update
RUN apt-get install -y docker-ce
#RUN usermod -aG docker ${USER}
RUN apt-get update
RUN curl -fsSL -o /tmp/lando-latest.deb http://installer.kalabox.io/lando-latest-dev.deb
RUN dpkg -i /tmp/lando-latest.deb
RUN lando version
But It's showing "lando command not found", Is anything I am missing, Please guide me.
Lando has essentially 3 dependencies:
Docker (Docker CE on Linux)
Docker-Compose
NodeJS (Typically the current LTS)
A container trying to run Lando itself should probably run from the [Docker][1] image, with all the typical "Docker in Docker" modifications and caveats such is possibly mounting the docker socket in the container, and running privileged mode, etc.
Your example is running from Lando's PHP FPM base image, which isn't at all designed to run either Docker or Node. It also isn't based on Ubuntu, but rather Debian directly (and you are including some Ubuntu specific code for installing Docker).
All that said, running Lando from within a Docker container is likely to run into issues with permissions and volume mounts among potential other things. It isn't recommended, though it might be possible.
Here is a Dockerfile from a small repo I made a few years back that worked to install an old version of Lando in a Dockerfile, it could help you make a more up to date one:
FROM ubuntu:bionic
RUN mkdir -p /root/.bin && touch /root/.zshrc
RUN apt update && apt upgrade -y && apt install -y \
git \
exuberant-ctags \
neovim \
python3-pip \
software-properties-common \
wget \
zsh
RUN chsh -s $(which zsh)
RUN add-apt-repository ppa:martin-frost/thoughtbot-rcm \
&& apt update \
&& apt install rcm -y
RUN git clone https://github.com/thinktandem/dotfiles.git ~/dotfiles \
&& mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config} \
&& mkdir -p $XDG_CONFIG_HOME/nvim \
&& ln -s ~/.vim/autoload ~/.config/nvim/ \
&& ln -s ~/.vimrc $XDG_CONFIG_HOME/nvim/init.vim \
&& rcup
RUN git clone https://github.com/nodenv/nodenv.git ~/.nodenv
RUN git clone \
https://github.com/nodenv/node-build.git \
/root/.nodenv/plugins/node-build
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt remove cmdtest \
&& apt update \
&& apt install --no-install-recommends yarn -y
RUN add-apt-repository ppa:cpick/hub \
&& apt update \
&& apt install -y hub
RUN apt remove docker docker-engine docker.io \
&& apt install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| apt-key add - \
&& add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
bionic \
stable" \
&& apt update \
&& apt install -y docker-ce
RUN TEMP_DEB="$(mktemp)" \
&& wget -O "$TEMP_DEB" \
'https://github.com/lando/lando/releases/download/v3.0.0-rc.1/lando- v3.0.0-rc.1.deb' \
&& dpkg -i "$TEMP_DEB" \
&& rm -f "$TEMP_DEB"
RUN curl -L git.io/antigen > ~/antigen.zsh
RUN RCRC=$HOME/dotfiles/rcrc rcup
CMD ["/usr/bin/zsh"]

Resources