0

I have an existing custom service at /lib/systemd/system/custom.service with:

After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
User=customuser
ExecStart=/opt/customservice /opt/custom.config

[Install]
WantedBy=multi-user.target

With:

systemctl enable custom.service
systemctl start custom.service

How can I convert this service to a docker container, keeping in in foreground and always up and running?

I started with a Dockerfile as follows:

FROM ubuntu:20
COPY /custom.service /opt/app/
COPY /custom.config /opt/app/

ENTRYPOINT [ "/opt/custom.service", "/opt/custom.config" ]

But how can I now achieve the same configuration as I had in the native systemd service?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • I think that depends a lot on what the service actually is, how it takes its configuration, whether it normally daemonizes itself, and so on. You definitely would not include the systemd service file in the container; instead you'd set the main container command to actually run the process (I'd recommend doing it in `CMD` rather than `ENTRYPOINT` for being easier to debug and to adapt to some common Dockerfile patterns). – David Maze Oct 26 '22 at 13:04
  • It's a simple service that offers a socket port, if that helps. How would I have to start it and keep it alive with `CMD` instead? – membersound Oct 26 '22 at 13:09
  • Looking at the systemd unit file, is the command to run the process just `/opt/customservice /opt/custom.config`? Make that be the `CMD`. – David Maze Oct 26 '22 at 13:10
  • It's just exactly as in the question – membersound Oct 26 '22 at 13:13

0 Answers0