skip to Main Content

I’m trying to keep a devpi instance running inside a container throughout the build process so subsequent RUN commands can make use of it and populate it’s database during the build. e.g

FROM centos:centos7 
RUN pip install devpi
RUN devpi-server --host=0.0.0.0 --port=3141
RUN some other task that interacts with devpi-server
...

Is this possible? I’ve been unable to get it working so far

2

Answers


  1. Chosen as BEST ANSWER

    I figured it out. I needed to add a seperate shell script that both started devpi-server and performed the commands that interacted with it. Then I can start the process and interact with it within the same RUN command.

    FROM centos:centos7 
    RUN pip install devpi
    ADD start-devpi.sh
    RUN chmod +x start-devpi.sh
    RUN ./start-devpi.sh
    

    Where start-devpi.sh looks like

    devpi-server --host=0.0.0.0 &
    sleep 15 #wait for the server to come online
    put further commands that use the running devpi-server instance here
    ...
    

  2. I think if you want to run a certain command in the background you might need to run:

    nohup command &
    

    but in your case since you want to run it in background during image build time this might help you:

    FROM ubuntu:18.04
    
    RUN apt-get update
    RUN apt-get install -y inetutils-ping
    # Using sleep will give the command some time to be executed completely
    RUN sleep 10 ; ping localhost -c 3 > xxx.log
    

    As you can see I am running a sleep command and ping command simultaneously by separating them with ; let’s say in your example the estimated time to populate its database during the build might take around 2mins so setting sleep time close to that interval would solve ur problem.

    PS: Make sure to know the difference between RUN and CMD, since docker build will actually create a temporary container to test the RUN commands then remove it once the build is done.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search