Vagrant in Docker Container not working (trying to lint Vagrantfiles) - docker

I just don't get it right ... I'm trying to create a docker-container with vagrant installed to lint my Vagrantfiles in a Gitlab CI pipeline. But all I get ist this result:
$ cd src/main/kube-cluster && vagrant validate
==> vagrant: A new version of Vagrant is available: 2.2.16 (installed version: 2.2.6)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html
No usable default provider could be found for your system.
Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
environments. Examples are VirtualBox, VMware, Hyper-V.
The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.
If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.
For full pipeline, see https://gitlab.com/sommerfeld.sebastian/v-kube-cluster/-/pipelines/304344599
My Dockerfile is rather simple
FROM ubuntu:focal
LABEL maintainer="sommerfeld.sebastian#gmail.com"
# Avoid beeing stuck at tzdata
ENV TZ="Europe/Berlin"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y --no-install-recommends virtualbox=6.1.6-dfsg-1 virtualbox-qt=6.1.6-dfsg-1 virtualbox-dkms=6.1.6-dfsg-1 \
&& vboxmanage --version \
&& apt-get install -y --no-install-recommends ca-certificates=20210119~20.04.1 \
&& apt-get install -y --no-install-recommends curl=7.68.0-1ubuntu2.5 \
&& apt-get install -y --no-install-recommends libcurl4=7.68.0-1ubuntu2.5 \
&& curl -O https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.deb \
&& apt-get install -y --no-install-recommends ./vagrant_2.2.6_x86_64.deb \
&& vagrant --version \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
But anyway I try, I always get the abouve result from my pipeline. Anyone got an idea on how I can fix my Image?
Alternatively I'm also open to another way to lint my Vagrantfiles.

Related

running windows base application embedded in ubuntu or alpine based docker image

We developed Windows based application and try to convert it to run as docker in Linux base environment.
Unfortunately, one of 3rd party library can't be convert to Linux environment.
We built docker image which is ubuntu 16.04 + wine 4.0 + winetricks which our application can runs on it but all 3 components (ubuntu, wine + winetrick) weight more than 3GB.
Below is the part of Dockerfile which we use to build the docker image
Our application is 64bit and combines python and C++ code
How can we reduce docker size?
Is there another way to run windows base application as docker container on linux environment?
FROM ubuntu:16.04
# reccomended to add 32bit arch for wine
RUN dpkg --add-architecture i386 \
# install things to help install wine
&& apt-get update \
&& apt-get install -y --allow-unauthenticated wget software-properties-common software-properties-common debconf-utils python-software-properties apt-transport-https cabextract telnet xvfb unzip build-essential \
# register repo and install winehq
&& wget -nc https://dl.winehq.org/wine-builds/Release.key \
&& apt-key add Release.key \
&& wget -nc https://dl.winehq.org/wine-builds/winehq.key \
&& apt-key add winehq.key \
&& apt-add-repository https://dl.winehq.org/wine-builds/ubuntu/ \
&& apt-get update \
&& apt-get install -y xvfb \
&& apt-get install --install-recommends -y --allow-unauthenticated winehq-stable
# setup vars for wine
ENV DISPLAY=":0.0"
ENV WINEARCH="win64"
ENV WINEPREFIX="/root/.wine64"
ENV WINESYSTEM32="/root/.wine64/drive_c/windows/system32"
ENV WINEDLLOVERRIDES="mscoree,mshtml="
ENV WINEDEBUG=-all
COPY scripts /root/scripts
# pull down winetricks, and install requirements
# vcrun2015 and vcrun2010 are Visual Studio C++ Redistributables
RUN set -e \
&& mkdir -p $WINEPREFIX \
&& cd $WINEPREFIX \
&& wget https://raw.githubusercontent.com/Winetricks/winetricks/20190615/src/winetricks \
&& chmod +x winetricks \
&& xvfb-run wine wineboot --init \
&& xvfb-run wineserver -w \
&& xvfb-run sh ./winetricks -q d3dx9 corefonts vcrun2015
RUN set -x \
&& pythonVersions='python3.7' \
&& apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends software-properties-common \
&& apt-add-repository -y ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends $pythonVersions \
&& rm -rf /var/lib/apt/lists/* \
...
You install many unneeded packages, you should read carefully
https://www.dajobe.org/blog/2015/04/18/making-debian-docker-images-smaller/
which explains why
You should remove xvfb (I guess you need xvfb during the installation and configuration of wine, but not after) and all the "recommended" packages
Look also at
https://github.com/wagoodman/dive
which is an excellent tool if you need to see how efficient is your docker image
Use also
https://github.com/jwilder/docker-squash
it can save some space.
Good hunt

How to run glut app inside docker without FBConfig error?

So, I need to develop and run a specific gui app on Ubuntu. Application is based on OpenGL and freeglut. I'd like to develop from macbook, so I tried to use the vs code remote container feature. It worked well, until I needed to run this app. I installed a lot of various gl packages inside container, ran it with xquarts and etc.
And now I met the problem with glut: freeglut (my_app): ERROR: Internal error <FBConfig with necessary capabilities not found> in function fgOpenWindow. As I found there, it's a known bug with glut and remote connection. And it's known from 2009! So does anyone know, how to get rid of it? Or I will never run my app inside docker?
My current Dockerfile:
FROM nvidia/cudagl:9.0-devel-ubuntu16.04
# This Dockerfile's base image has a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=user
ENV DEBIAN_FRONTEND noninteractive
# Adding new architecture in package base
RUN dpkg --add-architecture i386
# Installg tools
RUN apt-get update \
&& apt-get -y install sudo software-properties-common zsh wget
# Installing latest git
RUN add-apt-repository ppa:git-core/ppa \
&& apt-get update \
&& apt-get -y install git
# Install C++ tools
RUN apt-get -y install build-essential gcc-multilib g++-multilib cmake cppcheck valgrind
# Install some dependencies
RUN apt-get -y install libc6-dev-i386 libgl1-mesa-dev libglu1-mesa-dev freeglut3 freeglut3-dev libjpeg-turbo8-dev libpng12-dev mesa-utils
# Install dependencies with another architecture
RUN apt-get -y install libgl1-mesa-dev:i386 libglu1-mesa-dev:i386 freeglut3:i386 freeglut3-dev:i386 libpng12-0:i386
# Install nvidia driver
RUN apt-get install -y binutils xserver-xorg-video-all
# Adding new user
RUN groupadd --gid 2000 $USERNAME \
&& useradd --uid 2000 --gid $USERNAME --shell /bin/zsh --create-home $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
USER $USERNAME
ENV DEBIAN_FRONTEND interactive
I don't know how, but now it's working! I've tried to use so many things, so I don't know what exactly helped me. So I'll try to tell everything:
Docker base image become Ubuntu 14.04. I've already tried it before, but it didn't work then.
I've downgraded XQuartz to version 2.7.8
I've pasted this in terminal: defaults write org.macosforge.xquartz.X11 enable_iglx -bool true
Just in case, here is my new Dockerfile:
FROM ubuntu:14.04
# This Dockerfile's base image has a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=user
ENV DEBIAN_FRONTEND noninteractive
# Adding new architecture in package base
RUN dpkg --add-architecture i386
# Install tools
RUN apt-get update \
&& apt-get -y install sudo software-properties-common zsh wget
# Install last git
RUN add-apt-repository ppa:git-core/ppa \
&& apt-get update \
&& apt-get -y install git
# Install C++ tools
RUN apt-get -y install build-essential gcc-multilib g++-multilib cmake cppcheck valgrind
# Install some dependencies
RUN apt-get -y install libc6-dev-i386 libgl1-mesa-dev libglu1-mesa-dev freeglut3 freeglut3-dev libjpeg-turbo8-dev libpng12-dev mesa-utils
# Install dependencies with another architecture
RUN apt-get -y install libgl1-mesa-dev:i386 libglu1-mesa-dev:i386 freeglut3:i386 freeglut3-dev:i386 libpng12-0:i386
# Install nvidia driver
RUN apt-get install -y binutils xserver-xorg-video-all
# Adding new user
RUN groupadd --gid 2000 $USERNAME \
&& useradd --uid 2000 --gid $USERNAME --shell /bin/zsh --create-home $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
USER $USERNAME
ENV DEBIAN_FRONTEND interactive

install python3.6 on amazonlinux docker image

I have been experimenting to create a docker image with python3.6 based on amazonlinux.
So far, I have not been very successful. I use
docker run -it amazonlinux
to start an interactive docker terminal. Inside the terminal, I run "yum install python36" and see the following error message. Note that I copied this step was from an old amazonlinux based Dockerfile. This Dockerfile used to work. So I suspend the error I see below is due to amazon updated their docker linux image
bash-4.2# yum install python36
Loaded plugins: ovl, priorities
amzn2-core | 2.4 kB 00:00:00
No package python36 available.
Error: Nothing to do
I have tried to add a python3.6 repo by following this post
https://janikarhunen.fi/how-to-install-python-3-6-1-on-centos-7 however, it still gives the same error when I run
yum install python36u
Is there any way to add python3.6 to amazonlinux base layer? Thanks in advance.
There is now a far easier answer to this question thanks to aws 'extras'. Now this will work:
amazon-linux-extras install python3
You can check this Dockerfile based on amazon Linux and having python version is PYTHON_VERSION=3.6.4.
Or you can work with your existing one like
ARG PYTHON_VERSION=3.6.4
ARG BOTO3_VERSION=1.6.3
ARG BOTOCORE_VERSION=1.9.3
ARG APPUSER=app
RUN yum -y update &&\
yum install -y shadow-utils findutils gcc sqlite-devel zlib-devel \
bzip2-devel openssl-devel readline-devel libffi-devel && \
groupadd ${APPUSER} && useradd ${APPUSER} -g ${APPUSER} && \
cd /usr/local/src && \
curl -O https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
tar -xzf Python-${PYTHON_VERSION}.tgz && \
cd Python-${PYTHON_VERSION} && \
./configure --enable-optimizations && make && make altinstall && \
rm -rf /usr/local/src/Python-${PYTHON_VERSION}* && \
yum remove -y shadow-utils audit-libs libcap-ng && yum -y autoremove && \
yum clean all
But better to clone the repo and make your own image form that.
I too had similiar issue for docker.
yum install docker
Loaded plugins: ovl, priorities
amzn2-core | 3.7 kB 00:00:00
No package docker available.
Error: Nothing to do
instead yum I used amazon-linux-extras, it worked
amazon-linux-extras install docker

Docker commands require keyboard interaction

I'm trying to create a Docker image for ripping CDs (using abcde).
Here's the relevant portion of the Dockerfile:
FROM ubuntu:17.10
MAINTAINER Graham Nicholls <graham#rockcons.co.uk>
RUN apt update && apt -y install eject vim ruby abcde
...
Unfortunately, the package "abcde" pulls in a mail client (not sure which), and apt tries to configure that by asking what type of mail connection to configure (smarthost/relay etc).
When docker runs, it's not appearing to read from stdin, so I can't redirect into the docker process.
I've tried using --nodeps with apt (and replacing apt with apt-get); unfortunately --nodeps seems no-longer to be a supported option and returns:
E: Command line option --nodeps is not understood in combination with the other options
Someone has suggested using expect in response to a similar question, which I'd rather avoid. This seems to be a "difficult to google" problem - I can't find anything.
So, is there a way of passing in the answer to the config in apt, or of preventing apt from pulling in a mail client, which would be better - I'm not planning in sending updates to cddb.
The typical template to install apt packages in a docker container looks like:
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
eject \
vim \
ruby \
abcde \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Running it with the "noninteractive" value removes any prompts. You don't want to set that as an ENV since that would also impact any interactive commands you run inside the container.
You also want to cleanup the package database when finished to reduce the layer size and avoid reusing a stale cached package database in a later step.
The no-install-recommends option will reduce the number of packages installed by only installing the required dependencies, not the additional recommended packages. This cuts the size of the root filesystem down by half for me.
If you need to pass a non-default configuration to a package, then use debconf. First run you install somewhere interactively and enter the options you want to save. Install debconf-utils. Then run:
debconf-get-selections | grep "${package_name}"
to view all the options you configured for that package. You can then pipe these options to debconf-set-selections in your container before running your install, e.g.:
RUN echo "postfix postfix/main_mailer_type select No configuration" \
| debconf-set-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....
or save your selections to a file that you copy in:
COPY debconf-selections /
RUN debconf-set-selections </debconf-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....

Unable to use sudo commands within Docker, "bash: sudo: command not found" is displayed

I have installed TensorFlow using the following command
docker run -it b.gcr.io/tensorflow/tensorflow:latest-devel
and I need to set up TensorFlow Serving on a windows machine. I followed the instructions and while running the below-mentioned sudo command while installing TensorFlow Serving dependencies:
sudo apt-get update && sudo apt-get install -y \
build-essential \
curl \
git \
libfreetype6-dev \
libpng12-dev \
libzmq3-dev \
pkg-config \
python-dev \
python-numpy \
python-pip \
software-properties-common \
swig \
zip \
zlib1g-dev
The following error is displayed:
bash: sudo: command not found
docker comes along with root it doesnt require sudo.
BTW if you want sudo in docker if you want to install sudo,
try this,
apt-get update && \
apt-get -y install sudo
now you can use sudo along with your command in docker...
Docker images typically do not have sudo, you are already running as root by default. Try
apt-get update && apt-get install -y build-essential curl git libfreetype6-dev libpng12-dev libzmq3-dev pkg-config python-dev python-numpy python-pip software-properties-common swig zip zlib1g-d
If you wish to not run as root, see the Docker documentation on the User command.
We don't want to weaken the security of the container by installing sudo in it. But we also don't want to change existing scripts that work on normal machines just so that they work in docker, which doesn't need the sudo.
Instead, we can define a dummy bash script to replace sudo, which just executes the arguments without elevating permissions, and is only defined inside the docker image.
Add this to your Dockerfile:
# Make sudo dummy replacement, so we don't weaken docker security
RUN echo "#!/bin/bash\n\$#" > /usr/bin/sudo
RUN chmod +x /usr/bin/sudo

Resources