DockerFile SpringBoot App with Filebeat - docker

I have a simple Spring Boot App that is dockerized, with this simple DockerFile
FROM openjdk
MAINTAINER matteoroxis
ADD target/example-service.jar example-service.jar
ENTRYPOINT ["java", "-jar", "/example-service.jar"]
EXPOSE 2222
I have necessity to use Filebeat to send log to a logstash environment; how can I launch Filebeat using my DockerFile?

FROM openjdk
MAINTAINER matteoroxis
ENV FILEBEAT_VERSION=1.2.3 \
FILEBEAT_SHA1=3fde7f5f5ea837140965a193bbb387c131c16d9c
COPY my-config/filebeat.yml /filebeat.yml
RUN set -x && \
apt-get update && \
apt-get install -y wget && \
wget https://download.elastic.co/beats/filebeat/filebeat-${FILEBEAT_VERSION}-x86_64.tar.gz -O /opt/filebeat.tar.gz && \
cd /opt && \
echo "${FILEBEAT_SHA1} filebeat.tar.gz" | sha1sum -c - && \
tar xzvf filebeat.tar.gz && \
cd filebeat-* && \
cp filebeat /bin && \
cd /opt && \
rm -rf filebeat* && \
apt-get purge -y wget && \
apt-get autoremove -y && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD target/example-service.jar example-service.jar
ENTRYPOINT ["java", "-jar", "/example-service.jar"]
CMD [ "filebeat", "-e" ]
EXPOSE 2222
Here is the filebeat dockerfile, for your reference

Related

Docker, cannot execute binary file: Exec format error

I have created Dockerfile, when i'm try to run a problem inside my container i'm getting error:
bash: xxx: cannot execute binary file: Exec format error
Dockerfile:
FROM debian:buster-slim
# Set the working directory to /usr/local/bin
WORKDIR /usr/local/bin
# Build container and setup wallet
RUN apt-get update -y && \
apt-get autoremove -y && \
apt-get install wget -y && \
wget https://euno.co/wallet/euno-2.0.2.tar.gz && \
tar zxvf euno-2.0.2.tar.gz && \
rm -rf euno-2.0.2.tar.gz && \
mkdir /root/.eunopay && \
chmod 755 euno*
# change working dir to eunopay folder
WORKDIR /root/.eunopay
# Download bootstrap
RUN wget https://euno.co/bootstrap/euno-bootstrap.tar.gz && \
tar zxvf euno-bootstrap.tar.gz && \
rm -rf euno-bootstrap.tar.gz && \
echo "server=1" >> euno.conf && \
echo "deamon=1" >> euno.conf && \
echo "debug=0" >> euno.conf
WORKDIR /root
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
Can anyone help me out what's going wrong?

docker-compose.yml - container with exited status on Ubuntu host

My docker-compose.yml:
version: "3.3"
services:
build_and_run_service:
image: myapp:0
build: .
network_mode: host
volumes:
- './bin/cookie:/app/cookie'
- './bin/logs:/app/logs'
- './bin/warehouse:/app/warehouse'
Dockerfile doesn't contain CMD and ENTRYPOINT, so when I execute commands in that order:
docker build --tag myapp:0 .
docker run -d -t myapp:0
docker exec -it <container_id> /bin/bash
It works as expected.
For some reason the container is not working when using docker compose...
Commands order:
docker-compose up -d --build
docker-compose run -d build_and_run_service bash
What's wrong?
Both cases work fine on Windows but not on Ubuntu...
#edit
Dockerfile:
FROM ubuntu:20.04 as runtime
LABEL description="Build and run container - myapp"
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install -y nano
RUN apt-get install -y wget
RUN apt-get install -y curl
RUN apt-get install -y make
RUN apt-get install -y build-essential
RUN apt-get install -y tcl zlib1g-dev libssl-dev tk libcurl4-gnutls-dev libexpat1-dev gettext dos2unix
# Compilers
RUN apt-get install -y gcc-10
RUN apt-get install -y g++-10
RUN rm /usr/bin/gcc \
&& ln -s /usr/bin/gcc-10 /usr/bin/gcc
RUN rm /usr/bin/g++ \
&& ln -s /usr/bin/g++-10 /usr/bin/g++
# Postgres dev
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN wget --no-check-certificate --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y libpq-dev postgresql-server-dev-13
RUN cd /tmp \
&& wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1g.tar.gz \
&& tar -zxf openssl-1.1.1g.tar.gz \
&& cd openssl-1.1.1g \
&& ./config \
&& make \
&& make install \
&& rm /usr/bin/openssl \
&& ln -s /usr/local/bin/openssl /usr/bin/openssl \
&& ldconfig
RUN cd /tmp \
&& wget --no-check-certificate https://cmake.org/files/v3.19/cmake-3.19.6-Linux-x86_64.tar.gz \
&& tar -zxf cmake-3.19.6-Linux-x86_64.tar.gz \
&& mv cmake-3.19.6-Linux-x86_64 /usr/local/ \
&& ln -s /usr/local/cmake-3.19.6-Linux-x86_64/bin/cmake /usr/bin/cmake
RUN cd /tmp \
&& wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.0.tar.gz \
&& tar -zxf git-2.31.0.tar.gz \
&& cd git-2.31.0 \
&& make prefix=/usr/local all \
&& make prefix=/usr/local install
RUN cd /tmp \
&& wget --no-check-certificate https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz \
&& tar -zxf boost_1_75_0.tar.gz \
&& cd boost_1_75_0 \
&& ./bootstrap.sh \
&& ./b2 \
&& ./b2 install
VOLUME ["/app/cookie", "/app/logs", "/app/warehouse"]
WORKDIR /app
COPY . /src
RUN cd /src \
&& mkdir build \
&& cd build
# Some building command
## PRIVATE ##
# Removes tmp
RUN cd /tmp \
&& rm -r *

NVIDIA Driver Not found during Nvidia + Cuda - Docker Image build

I am trying to create a GPU microservice using Nvidia cuda Base image, but during the docker build, I am facing Driver not found issue, can someone point out what is missing here?
DockerFile:
FROM nvidia/cuda:10.1-devel
# Install some basic utilities
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*
ENV CONDA_AUTO_UPDATE_CONDA=false
ENV PATH=/home/user/miniconda/bin:$PATH
RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh \
&& chmod +x ~/miniconda.sh \
&& ~/miniconda.sh -b -p ~/miniconda \
&& rm ~/miniconda.sh \
&& conda install -y python==3.7 \
&& conda clean -ya
ENV PATH="/usr/local/cuda-10.1/bin:$PATH"
ENV LD_LIBRARY_PATH="/usr/local/cuda-10.1/lib64:$LD_LIBRARY_PATH"
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
ENV NVIDIA_VISIBLE_DEVICES=all
ENV FORCE_CUDA="1"
RUN conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch
RUN pip install -v -e .
Error:
"/home/user/miniconda/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1013, in _get_cuda_arch_flags
capability = torch.cuda.get_device_capability()
File "/home/user/miniconda/lib/python3.7/site-packages/torch/cuda/__init__.py", line 320, in get_device_capability
prop = get_device_properties(device)
File "/home/user/miniconda/lib/python3.7/site-packages/torch/cuda/__init__.py", line 325, in get_device_properties
_lazy_init() # will define _get_device_properties and _CudaDeviceProperties
File "/home/user/miniconda/lib/python3.7/site-packages/torch/cuda/__init__.py", line 196, in _lazy_init
_check_driver()
File "/home/user/miniconda/lib/python3.7/site-packages/torch/cuda/__init__.py", line 101, in _check_driver
http://www.nvidia.com/Download/index.aspx""")
AssertionError:
Found no NVIDIA driver on your system. Please check that you
have an NVIDIA GPU and installed a driver from
http://www.nvidia.com/Download/index.aspx
The issues happens during execution of last step in docker file.
I tried using multiple Nvidia base docker images, but didn't help much. (cuda:10.1-base-ubuntu18.04, cuda:10.1-runtime-ubuntu18.04)
Any pointers appreciated.
After lot of trial and errors and going through a lot of documentation, this is what worked fine.
ARG PYTORCH=1.3
ARG CUDA=10.1
ARG CUDNN=7
FROM pytorch/pytorch:1.3-cuda10.1-cudnn7-devel
RUN mkdir /app
WORKDIR /app
ENV TORCH_CUDA_ARCH_LIST="5.2 6.0 6.1 7.0+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"
RUN apt-get update && apt-get install -y libglib2.0-0 libsm6 libxrender-dev libxext6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install some basic utilities
RUN apt-get update && apt-get install -y \
curl \
ca-certificates \
sudo \
git \
bzip2 \
libx11-6 \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential g++ \
libglib2.0-0 libsm6 libxrender-dev libxext6 wget
# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' --shell /bin/bash user \
&& chown -R user:user /app
RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
USER user
# All users can use /home/user as their home directory
ENV HOME=/home/user
RUN chmod 777 /home/user
# Install Miniconda and Python 3.7
ENV CONDA_AUTO_UPDATE_CONDA=false
ENV PATH=/home/user/miniconda/bin:$PATH
RUN curl -sLo ~/miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh \
&& chmod +x ~/miniconda.sh \
&& ~/miniconda.sh -b -p ~/miniconda \
&& rm ~/miniconda.sh \
&& conda install -y python==3.7 \
&& conda clean -ya
RUN conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch
RUN pip install -v -e .
Hope this helps!
Good luck!

Python write permission denied in docker container

I'm trying to use pandas to write a csv to file in my flask app (wrapped with uwsgi) but I keep getting a permission denied error, despite adding uwsgi to my user-group, have I missed something?
docker buildfile:
FROM kennethreitz/pipenv as build
ADD . /app
WORKDIR /app
RUN pipenv install --deploy --system \
&& pipenv lock -r > requirements.txt \
&& pipenv run python setup.py bdist_wheel
FROM ubuntu:bionic
COPY --from=build /app/dist/*.whl .
ARG DEBIAN_FRONTEND=noninteractive
RUN set -xe \
&& apt-get update -q \
&& apt-get install -y -q \
python3-wheel \
python3-pip \
uwsgi-plugin-python3 \
&& python3 -m pip install *.whl \
&& apt-get remove -y python3-pip python3-wheel \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -f *.whl \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /app \
&& useradd _uwsgi --no-create-home --user-group
USER _uwsgi
ENTRYPOINT ["/usr/bin/uwsgi", \
"--master", \
"--enable-threads", \
"--die-on-term", \
"--plugin", "python3"]
CMD ["--http-socket", "0.0.0.0:8000", \
"--processes", "4", \
"--chdir", "/app", \
"--check-static", "static", \
"--module", "server:app"]

package.json file won't persist in docker container

I am trying to build a docker environment. I have made a Dockerfile which builds my image. Everything seems to work fine except for the issue that my package.json file won't persist inside the container. It seems as if it is getting removed somewhere. What I am doing wrong? Here is my Docker file content:
FROM ubuntu:14.04
RUN groupadd -r webuser && useradd -r -g webuser webuser && mkdir /home/webuser/ && chown webuser:webuser /home/webuser/
# install curl, apache, php
RUN sudo DEBIAN_FRONTEND=noninteractive \
apt-get -y update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:ondrej/php && \
apt-get -y update && \
apt-get install -y --force-yes \
curl \
git-core \
apache2 \
php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl \
php5.6-bz2 php5.6-zip && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
# install PHPUnit
RUN curl -L https://phar.phpunit.de/phpunit.phar -o phpunit.phar && \
chmod +x phpunit.phar && \
mv phpunit.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit
ADD package.json /var/www/html/package.json
WORKDIR /var/www/html
RUN chown -R webuser:webuser /var/www/html
USER webuser
# install node js 6
RUN NVM_DIR="/home/webuser/.nvm" && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && \
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
nvm install 6 && \
npm install -g webpack && \
npm install
RUN echo 'export NVM_DIR="/home/webuser/.nvm"\n\
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'\
>> /home/webuser/.bashrc
COPY src /var/www/html/
USER root
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Try changing your ADD command to the following :
RUN mkdir -p /var/www/html
ADD package.json /var/www/html
Also make sure the package.json is present in the
FROM ubuntu:14.04
ADD package.json /var/www/html/package.json
RUN groupadd -r webuser && useradd -r -g webuser webuser && mkdir /home/webuser/ && chown webuser:webuser /home/webuser/
# install curl, apache, php
RUN sudo DEBIAN_FRONTEND=noninteractive \
apt-get -y update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:ondrej/php && \
apt-get -y update && \
apt-get install -y --force-yes \
curl \
git-core \
apache2 \
php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl \
php5.6-bz2 php5.6-zip && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
# install PHPUnit
RUN curl -L https://phar.phpunit.de/phpunit.phar -o phpunit.phar && \
chmod +x phpunit.phar && \
mv phpunit.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit
WORKDIR /var/www/html
RUN chown -R webuser:webuser /var/www/html
USER webuser
# install node js 6
RUN NVM_DIR="/home/webuser/.nvm" && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && \
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
nvm install 6 && \
npm install -g webpack && \
npm install
RUN echo 'export NVM_DIR="/home/webuser/.nvm"\n\
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'\
>> /home/webuser/.bashrc
COPY src /var/www/html/
USER root
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
i have executed your Dockerfile and had the same problem. It works if the ADD is at the beginning of the Dockerfile. But there are some other problems. The build process is stopping right after
chmod +x /usr/local/bin/composer
it wont install PHPUnit and nodeJS, set owner of the www directory and so on.
Maybe you should chain the whole RUN into one.
It seems like we need to have the package.json file within the source directory. Copying package.json separately and running the npm install pattern is used to make use of docker's caching system.

Resources