Conditional ARG in Dockerfile? - dockerfile

I'm trying to conditionally install vim in my docker container if I pass an optional ARG - say something like DEVBUILD. I can't find any documentation on how to use something like IF in a Dockerfile. Something like this:
FROM node:8
if $DEVBUILD {
RUN apt-get update
RUN apt-get --assume-yes install vim
}
Is this possible, and if so, where can find a reference on the syntax?

Yes, it is possible. When docker builds image it uses standard shell.
Dockerfile is:
FROM node:8
ARG DEVBUILD
RUN if [ "x$DEVBUILD" != "x" ]; then apt-get update && apt-get --assume-yes install vim; fi
If you define variable DEVBUILD like, for example, DEVBUILD=true:
docker build . --no-cache --build-arg DEVBUILD=true
actions under if statement will be executed.

Related

How can I correct this Dockerfile to take arguments properly?

I have this dockerfile content:
FROM python:latest
ARG b=8
ARG r=False
ARG p=1
ENV b=${b}
ENV r=${r}
ENV p=${p}
# many lines of successful setup
ENTRYPOINT python analyze_all.py /analysispath -b $b -p $p -r $r
My intention was to take three arguments at the command line like so:
docker run -it -v c:\analyze containername -e b=16 -e p=22 -e r=False
But unfortunately, I'm misunderstanding something fundamental and simple here instead of something complicated, so I'm helpless :).
If I understood the question correctly, this Dockerfile should do what is required:
FROM python:latest
# test script that prints argv
COPY analyze_all.py /
ENTRYPOINT ["python", "analyze_all.py", "/analysispath"]
Launch:
$ docker run -it test:latest -b 16 -p 22 -r False
sys.argv=['analyze_all.py', '/analysispath', '-b', '16', '-p', '22', '-r', 'False']
Looks like your Dockerfile is designed to build and run a container on Windows. I tested my Dockerfile on Linux, it probably won't be much different to use this approach on Windows.
I think ARG instructions isn't needed in this case because it defines a variable that users can pass at build-time using the docker build command. I would also suggest that you take a look at the Dockerfile reference for the ENTRYPOINT instruction:
Command line arguments to docker run will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD. This allows arguments to be passed to the entry point, i.e., docker run -d will pass the -d argument to the entry point.
Also, this question will probably be useful for you: How do I use Docker environment variable in ENTRYPOINT array?

pathspec 'tools/n64 splat' did not match any file(s) known to git

so i tried castlevania game decomp and I follow this steps and I'm new to git
Inside the folder of your choice git clone https://github.com/Xeeynamo/sotn-decomp.git
Run sudo apt-get install -y $(cat tools/requirements-debian.txt) and everything worked
until this happen after i run this command: make update-dependencies
I got this error pathspec 'tools/n64 splat' did not match any file(s) known to git any idea on how to fix it, plz? I searched so much.
And this is the link to the decomp: https://github.com/Xeeynamo/sotn-decomp

Does Dockerfile support inline comments? [duplicate]

I am writing a Dockerfile. Is there a way to make comments in this file?
Does Docker have a comment option that takes the rest of a line and ignores it?
You can use # at the beginning of a line to start a comment (whitespaces before # are allowed):
# do some stuff
RUN apt-get update \
# install some packages
&& apt-get install -y cron
#'s in the middle of a string are passed to the command itself, e.g.:
RUN echo 'we are running some # of cool things'
As others have mentioned, comments are referenced with a # and are documented here. However, unlike some languages, the # must be at the beginning of the line. If they occur part way through the line, they are interpreted as an argument and may result in unexpected behavior.
# This is a comment
COPY test_dir target_dir # This is not a comment, it is an argument to COPY
RUN echo hello world # This is an argument to RUN but the shell may ignore it
It should also be noted that parser directives have recently been added to the Dockerfile which have the same syntax as a comment. They need to appear at the top of the file, before any other comments or commands. Originally, this directive was added for changing the escape character to support Windows:
# escape=`
FROM microsoft/nanoserver
COPY testfile.txt c:\
RUN dir c:\
The first line, while it appears to be a comment, is a parser directive to change the escape character to a backtick so that the COPY and RUN commands can use the backslash in the path. A parser directive is also used with BuildKit to change the frontend parser with a syntax line. See the experimental syntax for more details on how this is being used in practice.
With a multi-line command, the commented lines are ignored, but you need to comment out every line individually:
$ cat Dockerfile
FROM busybox:latest
RUN echo first command \
# && echo second command disabled \
&& echo third command
$ docker build .
Sending build context to Docker daemon 23.04kB
Step 1/2 : FROM busybox:latest
---> 59788edf1f3e
Step 2/2 : RUN echo first command && echo third command
---> Running in b1177e7b563d
first command
third command
Removing intermediate container b1177e7b563d
---> 5442cfe321ac
Successfully built 5442cfe321ac
Use the # syntax for comments
From: https://docs.docker.com/engine/reference/builder/#format
# My comment here
RUN echo 'we are running some cool things'
Dockerfile comments start with #, just like Python.
kstaken has good examples:
# Install a more-up-to date version of MongoDB than what is included in the default Ubuntu repositories.
FROM ubuntu
MAINTAINER Kimbro Staken
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
RUN echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list
RUN apt-get update
RUN apt-get -y install apt-utils
RUN apt-get -y install mongodb-10gen
#RUN echo "" >> /etc/mongodb.conf
CMD ["/usr/bin/mongod", "--config", "/etc/mongodb.conf"]
Docker treats lines that begin with # as a comment, unless the
line is a valid parser directive. A # marker anywhere else in a line
is treated as an argument.
example code:
# this line is a comment
RUN echo 'we are running some # of cool things'
Output:
we are running some # of cool things
Format
Here is the format of the Dockerfile:
We can use # for commenting purpose, as for example #COMMENT
#FROM microsoft/aspnetcore
FROM microsoft/dotnet
COPY /publish /app
WORKDIR /app
ENTRYPOINT ["dotnet", "WebApp.dll"]
From the above file when we build the docker, it skips the first line and goes to the next line because we have commented it using #
# this is comment
this isn't comment
is the way to do it. You can place it anywhere in the line and anything that comes later will be ignored

C++ linux install executable file on deploy environment

Hello every one i need to deploy linux(centos) c++ project with make file or script. By one makefile or script install dependency and project executable binary.
my dependency applications libboost-devel,gcc-g++ and pcre. my excuteble binary file is run_excute
Yip sure - put the below commands into a file. At the top of the file add:
#!/bin/bash
Save the file - lets say you call it install; on the command line type:
chmod +x ./install
Then to build and install your program type:
sudo ./install
Alternatively, if you've got some time on your hands:
http://www.rpm.org/max-rpm/ch-rpm-build.html
As an example the basic rpm build process for fedora is:
Step 1: setup your machine to do packaging:
dnf install #development-tools fedora-packager rpmdevtools
rpmdev-setuptree
Step 2: source and Makefile
Place these in ~/rpmbuild/SOURCES
Step 3: Create a spec file
In ~/rpmbuild/SPECS create file called myname.spec. It should contain something like:
Summary: My program description
Name: myname
Version: 0.0.0
Release: 0
License: GPLv2
Group: Applications/Databases
Source: https://xyz.tar.gz
URL: http://myurl
BuildRequires: libicu-devel
BuildRequires: pcre-devel
%description
A couple of lines describing the package
%prep
%setup -q
%build
cd %{myname}/source
make %{?_smp_mflags}
%install
%make_install
%files
%{_bindir}/*
%changelog
* Tue Nov 10 2015 Yours Truly <me#somewhere.com> - 0.0.0-0
- Some change comments
Step 4: create the source and binary rpm
cd ~/rpmbuild/SPECS
rpmbuild -ba myname.spec
Step 5: use the rpm
cd ~/rpmbuild/RPMS/x86_64
rpm -Uvh ./myprogram-version-release.a.whole.lot.of.stuff.rpm
To install the dependencies use yum, so:
sudo yum install libboost-devel
sudo yum group install "Development Tools"
sudo yum install pcre-devel
To build the application, move to the directory with the makefile in it and do:
make
sudo make install
Finally to run the application
./run_excute
or if your lucky
run_excute
will work.

How to build dolphin on Ubuntu 14.04.3 LTS (Trusty Tahr)

I am not a Linux pro, but I have a task to modify KDE app "dolphin" for home using (modify address bar navigation mechanism). I think, that it would easy, but still have no understanding how to do this. Days of tries led me to the solution, that I should not build dolphin from dolphin repository (git://anongit.kde.org/dolphin), but from kde-baseapps repo:
sudo apt-get update
sudo apt-get install git-core build-essential libkactivities-dev
sudo apt-get build-dep dolphin
git clone git://anongit.kde.org/kde-baseapps && cd kde-baseapps && mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` ..
make -j3
cd dolphin/src/
./dolphin4
Next I think, that I can find source code in "kde-baseapps" folder, but it references to "/usr/include" *.h-files, that references to corresponding *.cpp-files in "kdelibs" package.
That's right, that I should download "kdelibs" sources, modify them and build? That is right way to resolve task or exists a better way to do this?
Yeah, exists a better solution. kdelibs compilation isn't necessary, it is possible to modify only dolphin source code by this bash commands (from ~ dir):
mkdir src
cd src
sudo apt-get update
sudo apt-get build-dep kde-baseapps
apt-get source kde-baseapps
cd kde-baseapps-4.13.3/dolphin/src/
patch < ~/your.patch
cd ../..
mkdir build
cd build
cmake ..
make
sudo make install