skip to Main Content

I need to create a custom docker image with Cockpit and ubuntu.
But I can’t start the service and expose it once it has been installed.

FROM ubuntu:latest

ENV DEBIAN_FRONTEND=noninteractive TZ=Australia/Brisbane

RUN apt-get update -qq -y && apt-get upgrade -y && 
    apt-get install -y curl net-tools && 
    apt-get install -y cockpit


EXPOSE 9090

CMD [ "command to run and expose cockpit" ]

I tried with:

service cockpit.socket start && tail -f /dev/null

# And
service cockpit start && tail -f /dev/null

Error: Service not found: cockpit.socket

And also with:

CMD [ "cockpit" ]

Error: Command not found

Also it seems I can’t use systemctl in a docker Image.

2

Answers


  1. nstead of starting the service using systemctl, you can directly start the Cockpit service using its binary and then run it in the foreground. Here’s how you can modify your Dockerfile:

    FROM ubuntu:latest

    ENV DEBIAN_FRONTEND=noninteractive TZ=Australia/Brisbane

    RUN apt-get update -qq -y && apt-get upgrade -y &&
    apt-get install -y curl net-tools &&
    apt-get install -y cockpit

    Expose the Cockpit port

    EXPOSE 9090

    Start Cockpit in the foreground

    CMD ["cockpit", "-f"]

    In this Dockerfile:

    We install Cockpit as before.
    We expose the Cockpit port 9090.
    We start Cockpit directly using the cockpit command with the -f flag, which tells it to run in the foreground.
    This way, when you run a container based on this Docker image, Cockpit should start automatically and be accessible on port 9090.

    Login or Signup to reply.
  2. RUN mkdir -p /etc/cockpit/ws-certs.d/
    RUN openssl req -newkey rsa:2048 -nodes -keyout /etc/cockpit/ws-certs.d/self-signed.key
    -x509 -days 365 -out /etc/cockpit/ws-certs.d/self-signed.crt
    -subj "/C=US/ST=State/L=City/O=Organization/OU=Organizational Unit/CN=localhost"

    CMD ["/usr/lib/cockpit/cockpit-ws"]

    add these lines to dockerfile Generate a self-signed SSL certificate
    Start Cockpit in the foreground

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