I want to run a temporary docker and execute several command in it:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
make clean_brutal; \
$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT); \
$(if $(COVERITY_MISRA_2012), \
$(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"; \
$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output build_results/results/HTML_2012, );'
but I het the following error:
Illegal character in pattern: .
[ERROR] No results found.
I want to know how to run command seperately in a running container?
like:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c 'make clean_brutal';
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT)'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(if $(FFFF), \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run $(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output'build_results/results/HTML_2012, );'
I know this doesn't work but to give an idea what I want to do
Related
Hello im new in docker and im having problem to build this:
MySQL install well
PhpMyadmin instal wel...
but in apache i have this error
error:
: not foundbin/pete_install.sh: 2:
/usr/local/bin/pete_install.sh: 110: Syntax error: end of file unexpected (expecting "then")
pete_install.sh
Line 1 to 10
#!/bin/bash
FILE=/var/www/html/.installed
if [ ! -f "$FILE" ]; then
echo "#######################################"
echo "Starting WordPress Pete installation..."
echo "#######################################"
rm -rf /var/www/html/Pete4
Linea 99 to 110
FILE=/var/www/.ssh/id_rsa.pub
if [ ! -f "$FILE" ]; then
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
chmod 600 -R /var/www/.ssh/id_rsa
chmod 600 -R /var/www/.ssh/id_rsa.pub
apachectl -DFOREGROUND
#systemctl start
#/etc/init.d/apache2 reload
echo "Loading apache..."
full file https://pastebin.com/1f5a3pJY
Most of time, the error causes because you write your script on windows, the line break on windows is \r\n, while on linux it's \n.
You should install some tools to change format, e.g.:
$ sudo apt-get update
$ sudo apt-get install -y dos2unix
$ dos2unix /usr/local/bin/pete_install.sh
Now I want to make a docker command run in frontend so that I could see the log output. Now I am using this command to run my docker container:
docker run -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server dolphinjiang/canal-server:v1.1.5
this is the Dockerfile of my project:
FROM centos:7
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo ZONE=\"Asia/Shanghai\" > /etc/sysconfig/clock
RUN rm -rf /etc/yum.repos.d/*.repo
COPY CentOS6-Base-163.repo /etc/yum.repos.d/
RUN yum clean all
RUN groupadd -g 2500 canal; useradd -u 2501 -g canal -d /home/canal -m canal
RUN echo canal:De#2018er | chpasswd; echo root:dockerroot | chpasswd
RUN yum -y update && yum -y install wget vi openssl.x86_64 glibc.x86_64 tar tar.x86_64 inetutils-ping net-tools telnet which file
RUN yum clean all
COPY jdk-8u291-linux-x64.tar.gz /opt
RUN tar -zvxf /opt/jdk-8u291-linux-x64.tar.gz -C /opt && \
rm -rf /opt/jdk-8u291-linux-x64.tar.gz && \
chmod -R 755 /opt/jdk1.8.0_291 && \
chown -R root:root /opt/jdk1.8.0_291
RUN echo 'export JAVA_HOME=/opt/jdk1.8.0_291' >> /etc/profile
RUN echo 'export JRE_HOME=$JAVA_HOME/jre' >> /etc/profile
RUN echo 'export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH' >> /etc/profile
RUN echo 'export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >> /etc/profile
RUN source /etc/profile
RUN yum install kde-l10n-Chinese -y
RUN yum install glibc-common -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV JAVA_HOME /opt/jdk1.8.0_291
ENV PATH $PATH:$JAVA_HOME/bin
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ADD canal-server /home/canal/
RUN chmod 755 /home/canal/bin
WORKDIR /home/canal/bin
RUN chmod 777 /home/canal/bin/restart.sh
RUN chmod 777 /home/canal/bin/startup.sh
RUN chmod 777 /home/canal/bin/stop.sh
RUN chmod 777 /home/canal/bin/config.sh
CMD /home/canal/bin/config.sh
this is the config.sh:
cat > /home/canal/conf/canal.properties <<- EOF
# register ip
canal.register.ip = ${HOSTNAME}.canal-server-discovery-svc-stable.testcanal.svc.cluster.local
# canal admin config
canal.admin.manager = canal-admin-stable:8089
canal.admin.port = 11110
canal.admin.user = admin
canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441
# admin auto register
canal.admin.register.auto = true
canal.admin.register.cluster =
EOF
sh /home/canal/bin/restart.sh
and this is the restart.sh:
#!/bin/bash
args=$#
case $(uname) in
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
;;
*)
bin_abs_path=$(cd $(dirname $0) ||exit ; pwd)
;;
esac
sh "$bin_abs_path"/stop.sh $args
sh "$bin_abs_path"/startup.sh $args
and this is the start.sh:
#!/bin/bash
current_path=`pwd`
case "`uname`" in
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
;;
*)
bin_abs_path=`cd $(dirname $0); pwd`
;;
esac
base=${bin_abs_path}/..
canal_conf=$base/conf/canal.properties
canal_local_conf=$base/conf/canal_local.properties
logback_configurationFile=$base/conf/logback.xml
export LANG=en_US.UTF-8
export BASE=$base
if [ -f $base/bin/canal.pid ] ; then
echo "found canal.pid , Please run stop.sh first ,then startup.sh" 2>&2
exit 1
fi
if [ ! -d $base/logs/canal ] ; then
mkdir -p $base/logs/canal
fi
## set java path
if [ -z "$JAVA" ] ; then
JAVA=$(which java)
fi
ALIBABA_JAVA="/usr/alibaba/java/bin/java"
TAOBAO_JAVA="/opt/taobao/java/bin/java"
if [ -z "$JAVA" ]; then
if [ -f $ALIBABA_JAVA ] ; then
JAVA=$ALIBABA_JAVA
elif [ -f $TAOBAO_JAVA ] ; then
JAVA=$TAOBAO_JAVA
else
echo "Cannot find a Java JDK. Please set either set JAVA or put java (>=1.5) in your PATH." 2>&2
exit 1
fi
fi
case "$#"
in
0 )
;;
1 )
var=$*
if [ "$var" = "local" ]; then
canal_conf=$canal_local_conf
else
if [ -f $var ] ; then
canal_conf=$var
else
echo "THE PARAMETER IS NOT CORRECT.PLEASE CHECK AGAIN."
exit
fi
fi;;
2 )
var=$1
if [ "$var" = "local" ]; then
canal_conf=$canal_local_conf
else
if [ -f $var ] ; then
canal_conf=$var
else
if [ "$1" = "debug" ]; then
DEBUG_PORT=$2
DEBUG_SUSPEND="n"
JAVA_DEBUG_OPT="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=$DEBUG_SUSPEND"
fi
fi
fi;;
* )
echo "THE PARAMETERS MUST BE TWO OR LESS.PLEASE CHECK AGAIN."
exit;;
esac
str=`file -L $JAVA | grep 64-bit`
if [ -n "$str" ]; then
JAVA_OPTS="-server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss256k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError"
else
JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m "
fi
JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
CANAL_OPTS="-DappName=otter-canal -Dlogback.configurationFile=$logback_configurationFile -Dcanal.conf=$canal_conf"
if [ -e $canal_conf -a -e $logback_configurationFile ]
then
for i in $base/lib/*;
do CLASSPATH=$i:"$CLASSPATH";
done
CLASSPATH="$base/conf:$CLASSPATH";
echo "cd to $bin_abs_path for workaround relative path"
cd $bin_abs_path
echo LOG CONFIGURATION : $logback_configurationFile
echo canal conf : $canal_conf
echo CLASSPATH :$CLASSPATH
$JAVA $JAVA_OPTS $JAVA_DEBUG_OPT $CANAL_OPTS -classpath .:$CLASSPATH com.alibaba.otter.canal.deployer.CanalLauncher 2>&1
echo $! > $base/bin/canal.pid
echo "cd to $current_path for continue"
cd $current_path
else
echo "canal conf("$canal_conf") OR log configration file($logback_configurationFile) is not exist,please create then first!"
fi
after I start the docker, it exit automaticlly, and the docker not startup, no log output. what should I do to make it run in frontend. after successs, switch to the backend. I also tried to run in deamon like this(make the container run background and not exit):
docker run -it -d -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server canal/canal-server:v1.1.5
the process still exit automaticlly. and docker container did not startup.
Basically, you should get the point (based on your latest comment).
Docker is based on some command, when it's done - it stops the container.
So to make it continuously running you should have command and run infinitely.
Also check this answer as well, there are more explanation
Why docker exiting with code 0
One of the easiest solution is to tail some logs.
Like,
tail -f /dev/null
Taken from here
you can use tail -f /dev/null to keep the container from stopping, try this
docker run -it -d -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server canal/canal-server:v1.1.5 tail -f /dev/null
see also this post
I wrote "docker-compose.yml", and I want to execute two commands:
uwsgi -i /code/uwsgi.ini and python3.6 /code/manage.py collectstatic
I tried to use && to connect the two command, but it failed, what can I do?
You can execute multiple commands using bash -c:
command: >
bash -c "uwsgi -i /code/uwsgi.ini
&& python3.6 /code/manage.py collectstatic"
I am running the following Docker container from these Dockerfiles:
FROM debian:wheezy
MAINTAINER authors "authors#gm.com"
RUN groupadd -r -g 2200 example && \
useradd -rM -g example -u 2200 example
ENV APPROOT="/app" \
APP="mailer.sh" \
VERSION="0.6"
LABEL base.name="Mailer Archetype" \
base.version="${VERSION}"
WORKDIR $APPROOT
ADD . $APPROOT
ENTRYPOINT ["/app/mailer.sh"]
EXPOSE 33333
and
FROM dockerinaction/mailer-base:0.6
COPY ["./log-impl", "${APPROOT}"]
RUN chmod a+x ${APPROOT}/${APP} && \
chown example:example /var/log
USER example:example
VOLUME ["/var/log"]
CMD ["/var/log/mailer.log"]
where the mailer.sh is:
#!/bin/sh
printf "Logging Mailer has started.\n"
while true
do
MESSAGE=$(nc -l -p 33333)
printf "[Message]: %s\n" "$MESSAGE" > $1
sleep 1
done
All starts. But I want to test it. So i tried:
from the host to run "nc 33333" -> nothing happens!
to attach to the container: "docker exec -it /bin/bash" but then it does not recognize basic commands like "ps", "vi", "nc"...
So I am afraid my script is just not running.
Why is that?
thanks
This is my setup:
docker pull riot/riotbuild
wget https://github.com/RIOT-OS/RIOT/archive/2019.04.zip
unzip 2019.04.zip
cd RIOT-2019.04/examples/hello-world/
make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery all
All of this is OK.
make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery flash
This step failed. Error is :
> Building application "hello-world" for "stm32f4discovery" with MCU
> "stm32f4". "make" -C /data/riotbuild/riotbase/boards/stm32f4discovery
> "make" -C /data/riotbuild/riotbase/core "make" -C
> /data/riotbuild/riotbase/cpu/stm32f4 "make" -C
> /data/riotbuild/riotbase/cpu/cortexm_common "make" -C
> /data/riotbuild/riotbase/cpu/cortexm_common/periph "make" -C
> /data/riotbuild/riotbase/cpu/stm32_common "make" -C
> /data/riotbuild/riotbase/cpu/stm32_common/periph "make" -C
> /data/riotbuild/riotbase/cpu/stm32f4/periph "make" -C
> /data/riotbuild/riotbase/drivers "make" -C
> /data/riotbuild/riotbase/drivers/periph_common "make" -C
> /data/riotbuild/riotbase/sys "make" -C
> /data/riotbuild/riotbase/sys/auto_init "make" -C
> /data/riotbuild/riotbase/sys/isrpipe "make" -C
> /data/riotbuild/riotbase/sys/newlib_syscalls_default "make" -C
> /data/riotbuild/riotbase/sys/pm_layered "make" -C
> /data/riotbuild/riotbase/sys/stdio_uart "make" -C
> /data/riotbuild/riotbase/sys/tsrb text data bss dec
> hex filename 8756 140 2620 11516 2cfc
> /data/riotbuild/riotbase/examples/hello-world/bin/stm32f4discovery/hello-world.elf
> /home/huaxing/oproj/riot/RIOT-2019.04/dist/tools/openocd/openocd.sh
> flash
> /home/huaxing/oproj/riot/RIOT-2019.04/examples/hello-world/bin/stm32f4discovery/hello-world.elf
> Flashing Target sh: 1: openocd: not found
> /home/huaxing/oproj/riot/RIOT-2019.04/examples/hello-world/../../Makefile.include:538:
> recipe for target 'flash' failed make: *** [flash] Error 127
I check the script, in fact it will finally call docker as next:
a) make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery all
docker run --rm -t -u "$(id -u)" \
-v '/usr/share/zoneinfo/PRC:/etc/localtime:ro' -v '/home/shubuntu1/g/RIOT-2019.04:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase/examples/hello-world' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles' \
-e 'BOARD=stm32f4discovery' \
-w '/data/riotbuild/riotbase/examples/hello-world/' \
'riot/riotbuild:latest' make all 'BOARD=stm32f4discovery'
b) make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery flash
docker run --rm -t -u "$(id -u)" \
-v '/usr/share/zoneinfo/PRC:/etc/localtime:ro' -v '/home/shubuntu1/g/RIOT-2019.04:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase/examples/hello-world' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles' \
-e 'BOARD=stm32f4discovery' \
-w '/data/riotbuild/riotbase/examples/hello-world/' \
'riot/riotbuild:latest' make 'BOARD=stm32f4discovery'
They are nearly same, and the main use for container is just to build the source to stm32 binary as it's not add any permissions to control hardware when start container.
Compare to a), the b) also have next output:
### Flashing Target ###
sh: 1: openocd: not found
/home/shubuntu1/g/RIOT-2019.04/examples/hello-world/../../Makefile.include:538: recipe for target 'flash' failed
make: *** [flash] Error 127
This in fact not related to container, it runs on host, the root cause is you do not install openocd on host which used to flash the stm32 binary to device.
See this, search OpenOCD, it clear requires you to install openocd, then after the docker container finish the build, the binary will also be in host as it's in docker volume, and finally the openocd on host could flash your binary.