Custom unifi container

I’m trying to create a custom unifi controller container with a number of extras:

FROM jacobalberty/unifi:latest
RUN apt-get update -y && apt-get upgrade -y && apt-get install incron nano curl -y
ENTRYPOINT echo 'root' >> /etc/incron.allow && service incron start && /bin/bash

When I start this container, incron runs, but unifi does not.

I’ll try to explain what I’m looking for: a standard unifi controller with a local volume, incron to watch a certain file and start the incron service. The incron table is loaded from a local file and the service is running when I “ssh” into the container. Unifi however is not. Without the entrypoint line it does work, but the service does not run and on rebuilding I must always start it by hand.

FROM jacobalberty/unifi:latest
RUN apt-get update -y && apt-get upgrade -y && apt-get install incron nano curl -y && echo 'root' >> /etc/incron.allow

Am I using ENTRYPOINT the correct way? I have also tried CMD but this results in the container not running.

You changed the original entrypoint which is a long shell script: unifi-docker/docker-entrypoint.sh at 92880be3cd5b44b7fc26ed6f3781fe3c1fc2432d · jacobalberty/unifi-docker · GitHub

If you want to extend an entrypoint, create a new one which includes the original

docker-entrypoint-extended.sh

#!/usr/bin/env bash

echo 'root' >> /etc/incron.allow
service incron start

exec /usr/local/bin/docker-entrypoint.sh "$@"

Dockerfile

FROM jacobalberty/unifi:latest # really don't recommend to use the latest tag
RUN apt-get update -y && apt-get upgrade -y && apt-get install incron nano curl -y
COPY docker-entrypoint-extended.sh /usr/local/bin
RUN chmod +x /usr/local/bin/docker-entrypoint-extended.sh

ENTRYPOINT ["/usr/local/bin/docker-entrypoint-extended.sh"]

I have not tested it so if you try it you may need to improve the script.

Since I don’t know incron, I can’t say much about that but usually it is not a good practice to run services in a container like this. IIf you really need to run it as a deamon inside the container, I would try http://supervisord.org/

Thank you, I’ll give that a try. But first: you say to create a file which you call “docker-entrypoint-extended.sh” but I see “docker-entrypoint-custom.sh” in Dockerfile. Shouldn’t these have the same name? And where should I create that file? In the same directory as Dockerfile?

I wanted to call it docker-entrypoint-extended.sh and I forgot it immediatelly… so i wrote “-custom” later. I fixed my previous post, thanks :slight_smile:

It’s up to you but I wrote my example assuming that the file is in the root of the build context, which usually means that it is next to the Dockerfile.

Thanks again, I will test it and let you know my findings.

Based on your example I’m getting the following error: “/usr/local/bin/docker-entrypoint-extended.sh: line 6: /usr/local/bin/docker-entrypoint: No such file or directory”

I have tried correcting the file by changing “docker-entrypoint” to “docker-entrypoint.sh”, but that resulted in a container that didn’t want to start at all. I did find a file called docker-entrypoint.sh in the /usr/local/bin though when building a container based on the default image.

That was an other mistake in my post. I fixed it too.

Do you have log messages?

These are my logs:

Is this the full log? I assume these lines only the beginnings of the whole lines. What is it “exuting”? Is there an error code when you list the containers using docker container list --all?

I’m using Docker on Synology, this is the only thing that is logged.

647464267c1f unifi-incron:latest “/usr/local/bin/dock…” 32 seconds ago Exited (1) 28 seconds ago unifi-incron

I ran “sudo docker run -d -v etc” from the command line, this gave no other logs than those I posted before.

When I have a problem like this, I insert echos before every command. That way I know which command ran and which didn’t. So I checked the original entrypoint and realized it does something similar. The “Executing:” line in your logs shows that it tries to execute the command but it is probably empty.

We changed the original entrypoint and If I remember well, it resets the CMD. Try to add CMD ["unify"] to the end of the Dockerfile:

FROM jacobalberty/unifi:latest # really don't recommend to use the latest tag
RUN apt-get update -y && apt-get upgrade -y && apt-get install incron nano curl -y
COPY docker-entrypoint-extended.sh /usr/local/bin
RUN chmod +x /usr/local/bin/docker-entrypoint-extended.sh

ENTRYPOINT ["/usr/local/bin/docker-entrypoint-extended.sh"]
CMD ["unify"]

“unify” is what the original entrypoint expects as command as default. Otherwise it executes the command as is. When you don’t pass any arguments to the container, the default command is the value of CMD

1 Like

You’re the man! This works like a charm. One remark:

CMD ["unify"]

Should be:

CMD ["unifi"]

Sorry I can’t stop making typos :slight_smile: but I am glad it helped.