Docker Community Forums

Share and learn in the Docker community.

Dockerfile to run a yocto PRSERVER

(Aicastell) #1

Hello forum. I introduce myself. This is my first post in this forum, if there is a better place to publish this question, please let me know about it. Thank you for all your help in advance! :slight_smile:

The purpose is deploying a yocto PR service using a docker container. More info about PR service can be found in the following link:

To try doing that I wrote this Dockerfile to generate a docker image:

FROM ubuntu:16.04

# Update, upgrade and install
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y gawk wget git git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat xterm curl parted python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping libsdl1.2-dev net-tools

# Set up locales
RUN apt-get -y install locales apt-utils sudo && dpkg-reconfigure locales && locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG en_US.utf8

# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Replace dash with bash
RUN rm /bin/sh && ln -s bash /bin/sh

# Yocto user management
RUN groupadd -g 1000 yocto && useradd -u 1000 -g 1000 -ms /bin/bash yocto && usermod -a -G sudo yocto && usermod -a -G users yocto
ENV HOME /home/yocto
USER yocto

# Download poky
RUN git clone --branch rocko git:// /home/yocto/poky

# Create some directories
RUN mkdir -p /home/yocto/build /home/yocto/prserv

# Make /home/yocto/poky the working directory
WORKDIR /home/yocto/poky

# Expose listen port

# Run PR-servers
CMD /bin/sh -c " \
    source ./oe-init-build-env ../build \
    && bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585 \

Using previous Dockerfile I build a docker image:

    $ docker build -t docker-prserver .
    Successfully built 362f4599b1b6
    Successfully tagged docker-prserver:latest

As you can see before, the process ends successfully. After that, I run a container:

    $ docker run -ti docker-prserver

The previous command creates a shell. I check if the process “bitbake-prserver” is running:

yocto@b3c9fd06d8af:~/poky$ ps fax | grep bitbake

As you can see, the “bitbake-prserver” process is not running. However, if I log into the container and execute CMD command:

yocto@b3c9fd06d8af:~/poky/build$ source ./oe-init-build-env ../build/ && bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585
yocto@b3c9fd06d8af:~$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0  *               LISTEN     

Then it works fine.

It’s supposed that CMD is executed when the container is instantiated, but this is not happening. What is the right way to write a Dockerfile to run a bitbake-prserv server listening on the exposed port?

I know this question is close related with yocto, so I also will ask the same issue in the yocto mailing list.

Hope some of you have some experience on this and can provide any useful feedback.

Thanks a lot in advance! :slight_smile:

Kind regards,
– Ivan

(Aicastell) #2

I found the right way to fix my issue. First I wrote this script:

    $ cat 
    #! /bin/sh

    cd /home/yocto/poky
    source ./oe-init-build-env ../build
    bitbake-prserv --start --file /home/yocto/prserv/sqlite3.db --log /tmp/prserv.log --port 8585
    tail -f /tmp/prserv.log

And after modified the Dockerfile adding this stuff:

    ADD /home/yocto/
    RUN chmod 755 /home/yocto/
    RUN chown yocto.yocto /home/yocto/
    CMD /home/yocto/

Now it works as expected. Hope this helps somebody else!