Background:
I picked up an old server and started a Linux project a few months ago. I’ve been learning a ton and having a lot of fun. I’m using the server to host a number of sites (that are still in development because I’m also learning web-site development). Searching online I learned about SSL/TLS certificates, nginx, docker, and so on.
Using what I learned, I set up swag
to handle certificates and the reverse-proxy using docker-compose. I added my other sites to the same docker-compose.yaml file. After some struggles, I was able to get everything working the way I wanted. I had docker containers for each of my sites and stub sites for each of them. I could access them from any browser.
The first time I had to power off the server, when it came back up the docker containers did not all start up correctly. I was getting an “Address already in use” error on the swag
container. I googled for solutions and found this answer suggesting finding and killing the existing processes that were bound to the ports in question (80 and 443 for me) so that the docker container (the swag
container in my case) could be bound to them. The processes that I found that were using ports 80 and 443 were all “docker-proxy”. I killed them and I was able to restart the swag
docker container successfully without any errors. However, every time I restart or reboot the server, I must go through the same steps.
Also, even if I don’t power cycle the server, the docker containers seem to get restarted, and sometimes the swag
container doesn’t restart.
For example, as a test I shut down all my containers, edited the docker-compose file to only start swag and one website, and rebooted the server.
When I logged back in no containers were running. Good.
I killed docker-proxy (x4) and started the two containers.
thomas@server:~$ date
Fri 21 Jan 2022 09:40:13 PM UTC
thomas@server:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
thomas@server:~$ sudo lsof -i -P -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
[...]
docker-pr 2712 root 4u IPv4 48142 0t0 TCP *:443 (LISTEN)
docker-pr 2718 root 4u IPv6 44127 0t0 TCP *:443 (LISTEN)
docker-pr 2734 root 4u IPv4 43233 0t0 TCP *:80 (LISTEN)
docker-pr 2740 root 4u IPv6 48149 0t0 TCP *:80 (LISTEN)
[...]
thomas@server:~$ sudo kill 2712
thomas@server:~$ sudo kill 2718
thomas@server:~$ sudo kill 2734
thomas@server:~$ sudo kill 2740
thomas@server:~$ docker-compose up -d
Creating network "sites_default" with the default driver
Creating swag ... done
Creating turbobutterfly ... done
thomas@server:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d170fc643e20 ghcr.io/linuxserver/swag "/init" About a minute ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp swag
457b00fc0a8b turbobutterfly "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp turbobutterfly
thomas@server:~$ date
Fri 21 Jan 2022 09:42:54 PM UTC
thomas@server:~$
Then I sat back and watched, checking in periodically.
thomas@server:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d170fc643e20 ghcr.io/linuxserver/swag "/init" 5 hours ago Up 5 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp swag
457b00fc0a8b turbobutterfly "/docker-entrypoint.…" 5 hours ago Up 5 hours 80/tcp turbobutterfly
It has been up for five hours, seems okay.
thomas@server:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d170fc643e20 ghcr.io/linuxserver/swag "/init" 8 hours ago Up 3 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp swag
457b00fc0a8b turbobutterfly "/docker-entrypoint.…" 8 hours ago Up 3 hours 80/tcp turbobutterfly
It seems to have shut down 3 hours ago. And restarted okay.
thomas@zapdos:/home/sites$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d170fc643e20 ghcr.io/linuxserver/swag "/init" 19 hours ago Exited (255) 3 hours ago 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp swag
457b00fc0a8b turbobutterfly "/docker-entrypoint.…" 19 hours ago Up 3 hours 80/tcp turbobutterfly
I checked again in the morning. It seems to have shut down 3 hours ago. The website container restarted, but swag
didn’t.
This has been typical of what happens every time.
My questions:
- Why is docker restarting my containers?
I’ve checked the logs (using docker logs
) but I don’t see anything useful. For the swag
container, the logs show the start-up procedure, but nothing on shutdown. For the website container, it shows it receiving a SIGTERM
signal, but not why or from where.
Could it be something flaky with my hardware or my OS? Are there other logs somewhere to help identify possible issues? (I’m using an older PowerEdge that I got for free and Ubuntu 20.4 server).
-
When docker restarts my containers, why does
swag
sometimes not restart? -
What can I do so that the containers successful restart automatically when the server reboots (i.e. doesn’t conflict with
docker-proxy
on ports 80 and 443?
I would be very grateful for any assistance. This has been keeping me from moving forward on my projects for a few months.
If you need other information to help understand what’s wrong, please let me know.