0

I've created Dockerfile that is running gui, and after the container is executed I want it to run some bash script without freezing the container, so I am trying to run it as a background process but it seems like it's not executed at all.

Dockerfile:

FROM dorowu/ubuntu-desktop-lxde-vnc:latest
WORKDIR /data

COPY ./startup.sh /tmp/
COPY ./procedure.sh /tmp/

RUN chmod +x /tmp/startup.sh
RUN chmod +x /tmp/procedure.sh

CMD ["/tmp/startup.sh"]

startup.sh:

#!/bin/bash
cd /tmp && nohup ./procedure.sh > /dev/null 2>&1 &

procedure.sh:

#!/bin/bash
sleep 5

whoami > /tmp/log.txt

output=$(cat /tmp/log.txt)

My expectation is to have startup.sh executed when the container is started, and then run procedure.sh that will call to all of my flow.

As you can see I am printing the log into /tmp/log.txt but actually nothing is getting created once the container is started.

If I am running the script /tmp/startup.sh manually I can see the log.txt is getting created properly.

I will appreciate your help!

Itzik.B
  • 1,023
  • 2
  • 15
  • 35
  • Swap `CMD` with `ENTRYPOINT` – Paolo Apr 14 '23 at 07:15
  • @Paolo, After replacing `CMD` with `ENTRYPOINT` the container is not starting at all, I am running `docker run ....` and no container starts – Itzik.B Apr 14 '23 at 07:25
  • What does the `docker run` command look like? – Paolo Apr 14 '23 at 07:27
  • @Paolo, `docker run -p 5900:5900 -v /dev/shm:/dev/shm image` – Itzik.B Apr 14 '23 at 07:37
  • How are you assessing that nothing gets created? Since your container is a short lived one and that you are not mounting the folder `/tmp` to see the content of `log.txt`, when the container dies, the file vanish with it. – β.εηοιτ.βε Apr 14 '23 at 07:59
  • @β.εηοιτ.βε, Please notice this is a GUI container that is running forever and never die until I kill the process manually. – Itzik.B Apr 14 '23 at 08:03
  • @Itzik.B you seems to have an issue understanding the relation between CMD and ENTRYPOINT in Docker, may I suggest you reading the relevant documentation: https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact? – β.εηοιτ.βε Apr 14 '23 at 08:13
  • 1
    Also mind that your main image does simply ignore your CMD, as you can see by yourself in their entrypoint script not doing anything with with the arguments it receives: https://github.com/fcwu/docker-ubuntu-vnc-desktop/blob/develop/rootfs/startup.sh – β.εηοιτ.βε Apr 14 '23 at 08:15
  • I believe this is a duplicate because your command exits, and when that happens, the container stops. That happens immediately in your case since the command launches a background process and exits. – BMitch Apr 14 '23 at 09:21

0 Answers0