Add tcpdump in yocto build (Beaglebone Black) - beagleboneblack

I want to add tcpdump into yocto build
I found that I need to add meta-networking into bblayers.conf. meta-networking is apart of meta-openembedded
Following are the steps I followed :
Downloaded complete meta-openembedded : git clone git#github.com:openembedded/meta-openembedded.git
Checked out to jethro branch and confirmed that meta-networking/recipes-support/tcpdump/tcpdump_4.7.4.bb is present
Added meta-networking and its dependent packages into bblayers.conf
BBLAYERS
/home/linux/work/yocto/poky/meta-openembedded/meta-oe \
/home/linux/work/yocto/poky/meta-openembedded/meta-networking \
/home/linux/work/yocto/poky/meta-openembedded/meta-python \
Triggered full build and copied the images onto sdcard.
I am still unable to see tcpdump binary after booting up BBB(Beaglebone black). I am pretty sure I am missing something. I am new to yocto. Any guidance will be very helpful.

You need to add tcpdump to your image recipe. For a quick test, you add the following line to your conf/local.conf:
IMAGE_INSTALL_append = " tcpdump"
(Note the leading space in the assignment).
Just adding a layer won't add anything to your image.
Update:
In order to do do it correctly, you should add tcpdump to IMAGE_INSTALL in your own image recipe. Eg.
IMAGE_INSTALL += "tcpdump"
If you don't have your own image, you could add a <image-name>.bbappend file to your own layer, with the line above.

Related

Why does this docker image give back this error: Unable to access jarfile /home/server.jar

FROM "this line works but cant show code"
RUN yum install -y java-1.8.0-openjdk.x86_64 && yum clean all
COPY /resources/accounts.txt /home/resources/accounts.txt
COPY elk_casino_server /home/elk_casino_server
CMD ["jar","cvmf","/home/elk_casino_server/src/META-INF/MANIFEST.MF","/home/server.jar","/home/elk_casino_server/src/Main.class"]
CMD ["java","-jar","/home/server.jar"]
Please take a little more time to format your code snippets correctly and to make sure you ask a clear question.
Your Dockerfile uses the COPY instruction to copy two resources into your container image:
/resources/accounts.txt (available within the image at /home/resources/accounts.txt)
/elk_casino_server (available within the image at /home/elk_casino_server)
Unfortunately, your CMD instructions are trying to execute something very different. Only one command instruction can be defined and the latter will be accepted, which is:
CMD ["java","-jar","/home/server.jar"]
At no point do you copy /home/server.jar into your container image.
The parameter order of the char command seems to be wrong. The manifest-addition should come after the jar-file, not before it.
jar cfm jar-file manifest-addition input-file(s)
see: Packaging Programs in JAR Files: Modifying a Manifest File
Also: If there are more than one CMD, the last one overrides the others. Since I think you want to pack the jar at build time, RUN might be a better choice.
Both points combined:
RUN jar cvmf /home/server.jar /home/elk_casino_server/src/META-INF/MANIFEST.MF /home/elk_casino_server/src/Main.class

Compile inside Docker container without huge container sizes

I'm creating an auto-testing service for my university. I need to take student code, put it into the project directory, and run tests.
This needs to be done for multiple different languages in an extensible way.
My initial plan:
Have a "base image" for each language (i.e. install the language runtime on buildpack-deps:stretch)
Take user files & pre-made project structure
Put user files into the correct location in the project
Build an image of the project extending the base image
Run the container. It will compile the project and run tests.
Save test results to the database, stop & delete the image
Rinse repeat for every submission
When testing manually, the image sizes are huge! Almost 1.5GB in size! I'm installing the runtime for one language, and I was testing with Hello World - so the project wasn't big either.
This "works", but feels very inefficient. I'm also very new to Docker – is there a better way to do this?
Cheers
In this specific application, I'd probably compile the program inside a container and not build an image out of it (since you're throwing it away immediately, and the compilation and testing is the important part and, unusually, you don't need the built program for anything after that).
If you assume that the input file gets into the container somehow, then you can write a script that does the building and testing:
#!/bin/sh
cd /project/src/student
tar xzf "/app/$1"
cd ../..
make
...
curl ??? # send the test results somewhere
Then your Dockerfile just builds this into an image, without any specific student code in it
FROM buildpack-deps:stretch
RUN apt-get update && apt-get install ...
RUN adduser user
COPY build_and_test.sh /usr/local/bin
USER user
ADD project-structure.tar.gz /project
Then when you actually go to run it, you can use the docker run -v option to inject the submitted code.
docker run --rm -v $HOME/submissions:/app theimage \
build_and_test.sh student_name.tar.gz
In your original solution, note that the biggest things are likely to be the language runtime, C toolchain, and associated header files, and so while you get an apparently huge image, all of these things come from layers in the base image and so are shared across the individual builds (it's not taking up quite as much space as you think).

How to speed up Docker build

I'm trying to create a Dockerfile for a project I'm working on. Installing all the required packages through apt and pip takes a couple of minutes. Since the required packages don't change, is there a way so I can skip to the steps that do change?
I'm running Docker CE on OS X (version 17.06.2-ce-mac27).
Yes you can. Create two images
Dockerfile-base
FROM python:3.6
RUN pip install selenium
Then build using below
docker build -f Dockerfile-base -t base .
Dockerfile
FROM base
COPY . .
So you won't rebuild base. And keep on working on the main Dockerfile. There are other possible solutions also like deploying local Nexus package manager and using it to cache packages locally. But then too much of effort for a developer machine
If you use the docker cache each layer of the image will only be rebuilt if it has changed or the layer above has changed.
FROM alpine:latest # First layer
RUN apk add git gcc # Second layer
RUN apk add another-package # Third layer
If the first or second layers are changed (say you add openssl to the second line for example) the second and third layer will be rebuilt without using the cache.
But if only the third layer is changed, only that layer will have to rebuild, while the first and second layer is built from cache.
So sometimes you can move all the stuff that are supposed to be built rarely to the top of the file, and then let stuff that rebuild often be in its own layer further down (even though more layers increases image size).
If you rather move it into multiple images, you can absolutely do as Tarun says above.
If it is only data that you wish to move from one image to another (that is, not installed packages and such) you could check into multi-stage builds which allows you to define multiple images in a single file and let them copy data from the one built before in the file.
To get more information about how the build cache works, check out the docs!

Regarding not getting GNU awk version after creating a docker basic container

I am trying to create a normal docker's container, where I want to run my awk script. So we came to know we have to install GNU awk in it too, so could you please let me know if there any way we could get it in container itself(which creating os image) rather than installing it separately:
I apologies if I missed something here as I am new to this technology.
There are a couple of gawk-installed docker images publicly available. You may directly use one of them. A few examples: atarumix/gawk5-alpine algas/gawk. I have to note that most (if not all) are not actively maintained.
You may create a Dockerfile and install gawk. Although you mentioned you do not want to have a separate install, it is pretty easy. Consider this for example:
FROM alpine:latest
RUN apk add --no-cache gawk ffmpeg
If you do not want to use that docker file, you may push the generated image to an image repository. After you push the image, you shall be able to use the image directly. Details of push can be found at push reference.

How can I make my own base image for Docker?

According to the Docker documentation, to build your own image, you must always specify a base image using the FROM instruction.
Obviously, there are lots of images to choose from in the Docker index, but what if I wanted to build my own? Is that possible?
The image base is built off Ubuntu if I understand correctly, and I want to experiment with a Debian image. Plus, I want to really understand how Docker works, and the base image is still a blackbox for me.
Edit: official documentation on creating a base image
You can take a look at how the base images are created and go from there.
You can find them here: https://github.com/dotcloud/docker/tree/master/contrib.
There is mkimage-busybox.sh, mkimage-unittest.sh, mkimage-debian.sh
Quoting Solomon Hykes:
You can easily create a new container from any tarball with "docker import". For example:
debootstrap raring ./rootfs
tar -C ./rootfs -c . | docker import - flimm/mybase
(credit to fatherlinux) Get information from https://developers.redhat.com/blog/2014/05/15/practical-introduction-to-docker-containers/ , which explains better
Create the tar files for your file system, simply could be
tar --numeric-owner --exclude=/proc --exclude=/sys -cvf centos6-base.tar /
Transfer the tar file to other docker system if not installed locally and import it
cat centos6-base.tar | docker import - centos6-base
Now you can verify by running it.
docker run -i -t centos6-base cat /etc/redhat-release
The scripts from dotcloud combine first two steps together which make me confused and looks complicated in the beginning.
The docker official guideline using debootstrap also tries to make clean file system.
You can judge by yourself how to do step 1.
To start building your own image from scratch, you can use the scratch image.
Using the scratch “image” signals to the build process that you want the next command in the Dockerfile to be the first filesystem layer in your image.
FROM scratch
ADD hello /
CMD ["/hello"]
http://docs.docker.com/engine/articles/baseimages/#creating-a-simple-base-image-using-scratch
If you want to make your own base image I would first take a look at
Official Images, specifically stackbrew inside that repo.
Otherwise there are some great references for minimal OS images in the docker repo itself.
For example here is a script for making a minimal arch image and there are more here.

Resources