Skip to content

Instantly share code, notes, and snippets.

@jacknlliu
Last active January 5, 2022 10:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacknlliu/d9ead435ea44e6e3b6d7badfaf806cd2 to your computer and use it in GitHub Desktop.
Save jacknlliu/d9ead435ea44e6e3b6d7badfaf806cd2 to your computer and use it in GitHub Desktop.
use variable "DEBIAN_FRONTEND noninteractive" to apt-get noninteractive install and set environment and use shell script in Dockerfile
ENV QT_BASE_DIR=/opt/qt55
ENV QTDIR=$QT_BASE_DIR
ENV PATH=$QT_BASE_DIR/bin:$PATH
ENV LD_LIBRARY_PATH=$QT_BASE_DIR/lib/x86_64-linux-gnu:$QT_BASE_DIR/lib:$LD_LIBRARY_PATH
ENV PKG_CONFIG_PATH=$QT_BASE_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
# Reconfigure locale
RUN locale-gen en_US.UTF-8 && dpkg-reconfigure locales
# Docker offical ENVIRONMETN REPLACEMENT
ENV foo /bar
WORKDIR ${foo} # WORKDIR /bar
ADD . $foo # ADD . /bar
COPY \$foo /quux # COPY $foo /quux
# ENV like shell script syntax
ENV abc=hello
ENV abc=bye def=$abc
ENV ghi=$abc
# forked from docker.io [tstumm/qt-opencv](https://hub.docker.com/r/tstumm/qt-opencv/~/dockerfile/)
ENV DEBIAN_FRONTEND noninteractive
# Install updates & requirements:
# * git, openssh-client - for Drone
# * curl, p7zip - to download & unpack Qt bundle
# * build-essential, pkg-config, libgl1-mesa-dev - basic Qt build requirements
# * libsm6, libice6, libxext6, libxrender1, libfontconfig1 - dependencies of Qt bundle run-file
RUN apt-get -qq update && apt-get -qq dist-upgrade && apt-get install -qq -y --no-install-recommends \
git \
openssh-client \
ca-certificates \
curl \
p7zip \
build-essential \
pkg-config \
libgl1-mesa-dev \
libsm6 \
libice6 \
libxext6 \
libxrender1 \
libfontconfig1 \
&& apt-get -qq clean
# setup sshd login without passwd
RUN mkdir /var/run/sshd \
&& echo 'root:root' | chpasswd \
&& sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& echo "export VISIBLE=now" >> /etc/profile
# use "&&" and "\" to write a shell script in Dockerfile
# This is a compile/build source codes example in Dockerfile
RUN cd /opt \
&& wget https://github.com/Itseez/opencv/archive/3.0.0.zip \
&& unzip 3.0.0.zip \
&& cd opencv-3.0.0 \
&& mkdir release \
&& cd release \
&& cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. \
&& make -j4 \
&& make install \
&& bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' \
&& ldconfig \
&& rm /opt/3.0.0.zip \
&& rm -R /opt/opencv-3.0.0
# use ";" and "&&" and "\" to write shell script in Dockerfile
RUN /bin/bash -c "while true;do env | sort && sleep ${SLEEP_SECONDS:-30};done"
RUN /bin/bash -c "source /application.sh"
# The application.sh like the following lines:
# while true; \
# do env | sort && sleep ${SLEEP_SECONDS:-30}; \
# done
#
# command2
#
# command3
@ovuruska
Copy link

ovuruska commented Jan 5, 2022

Good to have examples. Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment