Exporting build files from docker container - docker

I have a docker image that builds a c/c++ embedded project and creates build artifacts.
I wrote a shell script which builds the code by using the docker image. It is intended be launched by the user on his machine to do debugging.
The build process work just fine and the files are created, but I'm not able to export them to the host machine for debugging.
I'm getting the error:
Error: No such container:path: builder:/usr/src/myCppProject/build/*.elf
This is my script:
#!/bin/bash
echo "Building docker image"
docker build --tag my-gcc:1.0 .
echo "Running docker container"
docker run -t -d --name builder --privileged my-gcc:1.0
echo "extracting artifacts"
docker cp builder:/usr/src/myCppProject/build/*.elf .
echo "Removing container"
docker stop builder
docker rm builder
echo "Cleaning up"
docker rmi $(docker images -f "dangling=true" -q)
the detailed output is:
...
/usr/src/myCppProject/LIBS/Shell/shell.h:80:76: warning: missing braces around initializer [-Wmissing-braces]
80 | sConsoleCMD_td s##name __attribute__ ((section(".shell_cmds"))) = {"MAGIC", (uint8_t*)#name, (uint8_t*)basic_desciption, (uint8_t*)detailed_description, (uint32_t)param_count, false, 0, CallBack, {0,0}}
| ^
/usr/src/myCppProject/APPS/main.c:32:1: note: in expansion of macro 'CON_CREATE_CMD'
32 | CON_CREATE_CMD(test, "test", "", 1, NULL);
| ^~~~~~~~~~~~~~
[100%] Linking C executable Testbench.elf
text data bss dec hex filename
25536 2044 7680 35260 89bc Testbench.elf
[100%] Built target Testbench.elf
Removing intermediate container 3d4a78e05b33
---> 8f2bfcfd19d7
Step 16/17 : WORKDIR /usr/src/myCppProject/build
---> Running in fd30a67e6d93
Removing intermediate container fd30a67e6d93
---> 5f0104d0b1e7
Step 17/17 : RUN ls
---> Running in 6096737dd094
CMakeCache.txt
CMakeFiles
Makefile
Testbench.bin
Testbench.elf
Testbench.hex
Testbench.map
cmake_install.cmake
Removing intermediate container 6096737dd094
---> 3624660a131b
Successfully built 3624660a131b
Successfully tagged my-gcc:1.0
Running docker container
4a31aee944118084602841f51b317df21b49d831345d78e652e36a3b2dfd1801
extracting artifacts
Error: No such container:path: builder:/usr/src/myCppProject/build/*.elf
Removing container
builder
...
Trying to use volumes is even worse, when calling:
mkdir build
docker run --name builder --privileged -v /build:/usr/src/myCppProject/build my-gcc:1.0
The script finishes successfully but the folder build on the host is empty :-( In my understanding whatever is but into build folder in the container should be also present in the just created build folder on the Host.
Thanks in advance e for your help.
Martin

OK finally I found it:
docker cp builder:/usr/src/myCppProject/build/*.elf does not work. It seems you need to specify the exact name.

Related

Oracle-xe docker container have weird behaviour

I am new to docker I have been trying to install oracel-18xe in the docker
after installing Oracele-xe which seems to be working but
after running ./buildContainerImage.sh command
I got the following logs.
Removing intermediate container 3cd9a901da82
---> 3ed5c215ef81
Step 7/8 : HEALTHCHECK --interval=1m --start-period=5m CMD "$ORACLE_BASE/$CHECK_DB_FILE" >/dev/null || exit 1
---> Running in a1c6507ac3b9
Removing intermediate container a1c6507ac3b9
---> f48555c74740
Step 8/8 : CMD exec $ORACLE_BASE/$RUN_FILE
---> Running in c36aec16a658
Removing intermediate container c36aec16a658
---> a347238232be
Successfully built a347238232be
Successfully tagged oracle/database:18.4.0-xe
which seems correct, Then I run the command
sudo docker run --name myxedb -d -p 51521:1521 -p 55500:5500 -e ORACLE_PWD=<secret> -e ORACLE_CHARACTERSET=AL32UTF8 oracle/database:18.4.0-xe
that runs with out error but after running docker logs command
I found the following logs.
sed: can't read /etc/oratab: No such file or directory
/opt/oracle/runOracle.sh: line 194: /etc/init.d/oracle-xe-18c: No such file or directory
grep: /etc/oratab: No such file or directory
#####################################
########### E R R O R ###############
DATABASE SETUP WAS NOT SUCCESSFUL!
Please check output for further info!
########### E R R O R ###############
#####################################
The following output is now a tail of the alert.log:
/opt/oracle/checkDBStatus.sh: line 18: oraenv: No such file or directory
tail: cannot open '/opt/oracle/diag/rdbms/*/*/trace/alert*.log' for reading: No such file or directory
tail: no files remaining
but when I run docker ps command I have not found any container running
then after googling I found an other variation the command
sudo docker run --name myxedb2 -d -i -t -p 51521:1521 -p 55500:5500 -e ORACLE_PWD=<secret> -e ORACLE_CHARACTERSET=AL32UTF8 oracle/database:18.4.0-xe /bin/bash
after that I was able to see the results in the docker ps command.
but docker logs command is showing nothing.
I have some questions here.
first of-all why the first docker run command was not running and docker logs command showing logs which is quite normal.
secondly why the second command is showing all good but docker logs are showing nothing.
and 3rdly the docker images command shows the following out put at my side
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 18.4.0-xe a347238232be 2 days ago 319MB
oraclelinux 7-slim 0a28ba78f4c9 7 weeks ago 132MB
but the forums I am following shows the the size which is quite different from my side.
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 18.4.0-xe 926f4349b277 12 minutes ago 5.89GB
oraclelinux 7-slim 153f8d73287e 8 weeks ago 131MB
Need suggesting and help needed here, thanks advance.
Regards,

Missing perl command in Perl image

I'm sure this is an incredibly simple fix. I tried to build Docker image with Perl in it (plus some Perl) modules. However, when I go to run this, it says there is no /bin/perl. The question is:
Why did the Perl Docker Image not have Perl in it?
My Dockerfile below:
FROM perl:5.20
ENV PERL_MM_USE_DEFAULT 1
RUN cpan install Net::SSL inc:latest
RUN mkdir /ssc
COPY /ssc /ssc
RUN mkdir /tmp/ssc-bin-files;cp /ssc/bin/*.sh /tmp/ssc-bin-files;chmod a+rx /tmp/ssc-bin-files/*;cp /tmp/ssc-bin-files/* /ssc/bin
RUN chmod a+rx /ssc/bin/*.sh
ENTRYPOINT ["/ssc/bin/put-and-submit.sh"]
Jenkins Pipeline snippet:
stage('Build, Tag and Push SSC Dockerfile'){
tagAsTest = "${IMAGE_NAME}:test"
REPO = "chq-ic2e-sprint-images-docker-local"
println "Docker App Build"
docker.build(tagAsTest,"-f Dockerfile .")
sh 'docker image ls | grep rules-client'
}
stage('Set image tag to :approved'){
hasReachedDockerComposeUp=false;
REPO = "chq-ic2e-sprint-images-docker-local"
sh "docker tag ${IMAGE_NAME}:test ${IMAGE_NAME}:approved"
buildInfo = rtDocker.push("${IMAGE_NAME}:approved", REPO , buildInfo)
server.publishBuildInfo buildInfo
}
The Jenkins log below:
[Pipeline] sh
+ docker build -t chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:test -f Dockerfile .
Sending build context to Docker daemon 39.42kB
Step 1/8 : FROM perl:5.20
---> bbe5a82c1dbe
Step 2/8 : ENV PERL_MM_USE_DEFAULT 1
---> Using cache
---> ca2769a89ab8
Step 3/8 : RUN cpan install Net::SSL inc:latest
---> Using cache
---> 1e53f0573131
Step 4/8 : RUN mkdir /ssc
---> Using cache
---> a324effec8ce
Step 5/8 : COPY /ssc /ssc
---> d40bf34f8565
Step 6/8 : RUN mkdir /tmp/ssc-bin-files;cp /ssc/bin/*.sh /tmp/ssc-bin-files;chmod a+rx /tmp/ssc-bin-files/*;cp /tmp/ssc-bin-files/* /ssc/bin
---> Running in 02386f41174f
Removing intermediate container 02386f41174f
---> 4767a8e6f23a
Step 7/8 : RUN chmod a+rx /ssc/bin/*.sh
---> Running in 07646aa96048
Removing intermediate container 07646aa96048
---> f070fcd8a9e9
Step 8/8 : ENTRYPOINT ["/ssc/bin/put-and-submit.sh"]
---> Running in e6bab12f8f40
Removing intermediate container e6bab12f8f40
---> 1422df9d957b
Successfully built 1422df9d957b
Successfully tagged chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:test
[Pipeline] sh
+ docker image ls
+ grep rules-client
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/rules-client approved da334d1d8fae 2 days ago 22.5MB
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/rules-client test da334d1d8fae 2 days ago 22.5MB
Script is being run via pipeline like this:
stage('Run image'){
sh '''
docker run -i -v \
--mount type=bind,source="$(pwd)/host-dirs,target=/host-dirs" \
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:approved
sh
'''
}
or from terminal like this:
#!/bin/bash
docker run -it \
--mount type=bind,source="$(pwd)/host-dirs,target=/host-dirs" \
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:approved sh
The perl binary is probably in /usr/local/bin/perl. You can check that in a shell in the running container.
host> docker exec -it your_container bash
container> which perl
/usr/local/bin/perl
container> exit
It sure has perl version 5.20 in it. I'm just curious about the entrypoint script in your dockerfile. You're running a shell script by default when the container is started. What the script starts or runs? If you want to run perl without entering the container, use --entrypoint=perl with your docker run command.
docker run --rm --name perl perl:5.20 perl --version
### Output
This is perl 5, version 20, subversion 3 (v5.20.3) built for x86_64-linux
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2015, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
###

Docker build step name cannot start with number

I'm building a docker image for a Sybase database. Docker build command fails because the name of the build step "server" cannot start with a number.
I have searched A LOT for a way to change the build step machine's name and my solution so far is to retry the build until I get a name that starts with a letter...
Step 1/7 : FROM my_image as docker_sybase_db
---> d266899b4eef
Step 2/7 : COPY *.zip /mnt/backup/
---> Using cache
---> 9e8e405848ce
Step 3/7 : COPY entrypoint.sh ~
---> Using cache
---> 5c0c923985db
Step 4/7 : ENV HOSTNAME docker_sybase_db
---> Using cache
---> f2b39a7280a0
Step 5/7 : RUN init_db.sh
---> Running in 0ae1a95b3203
Server name '0ae1a95b3203' begins with an illegal character. The first
character of a server name must be an alphabetic ascii character.
Error running command 'srvbuild -r /tmp/my_super_build.rs':
If I can't modify this old sybase init script, am I out of luck here ?
EDIT: Here is what I am trying to do
Create a database instance
Load a backup
Package that pre-loaded instance into a container.
Loading the backup takes a lot of time and this old database system requires the server name to start with a letter, not a number.
You could try and see if LolHens's idea of changing the hostname in the container namespace (during the docker build) works for you.
docker build . | tee >((grep --line-buffered -Po '(?<=^change-hostname ).*' || true) | \
while IFS= read -r id; do \
nsenter --target "$(docker inspect -f '{{ .State.Pid }}' "$id")"\
--uts hostname 'new-hostname'; \
done)
The docker build output is parsed to:
detect a "change-hostname" directive
do a nsenter, which runs a program in the UTS (UNIX Time Sharing) namespace, with a different hostname (different than the SHA-generated random one)
That means your RUN step should be:
RUN echo "change-hostname $(hostname)"; \
sleep 1; \
printf '%s\n' "$(hostname)" > /etc/hostname; \
printf '%s\t%s\t%s\n' "$(perl -C -0pe 's/([\s\S]*)\t.*$/$1/m' /etc/hosts)" "$(hostname)" > /etc/hosts; \
init_db.sh
That way, init_db.sh should run in an intermediate container with a different hostname (one you do have control over, and which would not start with a number).

Dockerfile RUN lpadmin to add a printer not working in the built image?

I want to add a printer in Dockerfile RUN command, so this is my Dockerfile
FROM dassh/eline:base
MAINTAINER dassh
# start cups service is necessary to run lpadmin command
RUN service cups start && lpadmin -p VLM2601 -v EleanBackend:/tmp -m
VLM2601_gdi.ppd -E && echo done
Build procedure
docker build -t dassh/eline .
Sending build context to Docker daemon 722.9kB
Step 1/3 : FROM dassh/eline:base
---> 712dce8cd557
Step 2/3 : MAINTAINER dassh
---> Running in 2f3f5f80b665
Removing intermediate container 2f3f5f80b665
---> 2b53b81d6ff4
Step 3/3 : RUN service cups start && lpadmin -p VLM2601 -v EleanBackend:/tmp -m VLM2601_gdi.ppd -E && echo done
---> Running in f176fbdf765e
* Starting Common Unix Printing System cupsd
...done.
done
Removing intermediate container f176fbdf765e
---> e229e278b085
Successfully built e229e278b085
Successfully tagged dassh/eline:latest
The build was successful without any error. But when I started a container with this image, I found that the printer wasn't added.
dassh#ubuntu:~$ docker run -itd dassh/eline /bin/bash
a8785057e71a598cd391f355848819295fef8e311090f70cbae95ca5360856c2
dassh#ubuntu:~$ docker cp ~/123.pdf a8:/
dassh#ubuntu:~$ docker attach a8
root#a8785057e71a:/pdf_to_prn#
root#a8785057e71a:/pdf_to_prn# service cups start
* Starting Common Unix Printing System cupsd [ OK ]
root#a8785057e71a:/pdf_to_prn# lp -o fit-to-page -o media=A4 -d VLM2601 /123.pdf
lp: The printer or class does not exist.
The command returns an error that the printer does not exist, but when I execute add printer command in the container manually, and run lp command again, everything is fine.
root#a8785057e71a:/pdf_to_prn# lpadmin -p VLM2601 -v EleanBackend:/tmp -m VLM2601_gdi.ppd -E
root#a8785057e71a:/pdf_to_prn# lp -o fit-to-page -o media=A4 -d VLM2601 /123.pdf
request id is VLM2601-1 (1 file(s))
Therefore, my adding printer command has no issues. So what is happening?
The problem cause by use lpadmin create printer.
system get printers by file /etc/cups/printers.conf.
use lpadmin add a printer will generate or update file /etc/cups/printers.conf.
step 2 is asynchronous! (It takes almost 30s in my test after execute lpadmin command)
Dockerfile RUN this step complete before file /etc/cups/printers.conf generated.

How to save a Docker image

I'm trying to follow a tutorial on https://www.ctl.io/developers/blog/post/docker-networking-rules/, which contains the following:
As I understand it, the code
FROM ubuntu:trusty
MAINTAINER Laura Frank <laura.frank#centurylink.com>
CMD while true; do echo 'hello world' | nc -l -p 8888; done
Is the content of a Dockerfile, which can be put in a newly created, empty directory and build using the command docker build ..
I don't quite understand however how to 'name' the image no-exposed-ports? Am I supposed to use tagging (the -t option) as in the example in https://docs.docker.com/engine/tutorials/dockerimages/?
I believe that by 'naming' the Docker image it is indeed meant that you use a tag. I used the command
docker build -t no-exposed-ports .
which gives the following response:
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:trusty
---> 3f755ca42730
Step 2 : CMD while true; do echo 'hello world' | nc -l -p 8888; done
---> Using cache
---> b8a7551d0ed9
Successfully built b8a7551d0ed9
From the command docker images I can see that no-exposed-ports is the name of the REPOSITORY, and the default tag latest has been assigned:
REPOSITORY TAG IMAGE ID CREATED SIZE
no-exposed-ports latest b8a7551d0ed9 18 minutes ago 188 MB
Finally, running with the command
docker run -d --name no-exposed-ports no-exposed-ports
produces a long hash as in the example on the blog:
eb39d8ef68826510f4c964ad586ff04b9e334433538d9d69a39aa0ec44d6701f

Resources