Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker, host-OS restart and busy ports

I started learning docker and I use it on Linux ubuntuserver 4.15.0-34-generic. I created container by this command:

sudo docker run -d --privileged --name FBSServer --hostname BACKUPSERVER --restart=always -p 4530:4530 -p 4531:4531 -v /home/adminek/synology:/fbs ferro/backupsystem FBS_Server

As you see container is listening on ports 4530 and 4531. When I ran this command for the first time, everything was OK. The container is running and I can communicate with an app using ports 4530/4531.

But after rebooting the host system the container is in Exited state

root@ubuntuserver:~# docker ps -a
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS                            PORTS               NAMES
6e77a4729847        ferro/backupsystem   "/start.sh FBS_Server"   7 hours ago         Exited (128) About a minute ago                       FBSServer

and I can not start the container. I see this:

root@ubuntuserver:~# docker container start FBSServer
Error response from daemon: driver failed programming external connectivity on endpoint FBSServer (c2afb35a61a18c65e8c306bbf36d4e2c9cdf428aafa386e12281d2d9e714b238): Error starting userland proxy: listen tcp 0.0.0.0:4531: bind: address already in use
Error: failed to start containers: FBSServer

In order to start I have to type these commands:

root@ubuntuserver:~# lsof -i :4530 | grep LISTEN
docker-pr 1328 root    4u  IPv6  35086      0t0  TCP *:4530 (LISTEN)
root@ubuntuserver:~# lsof -i :4531 | grep LISTEN
docker-pr 1316 root    4u  IPv6  35059      0t0  TCP *:4531 (LISTEN)

Then I kill the processes (in this example 1328 and 1316) and then I can start container by typing:

docker container start FBSServer

So the question number 1: Why after rebooting host system ports are "busy"?

and number 2: Why sometimes after rebooting host system I see that the changes in container were not saved? In other words - after reboot and made commands from above container is up, but it is in state without last changes I made a while before reboot the host.

like image 217
Madlon Avatar asked Sep 20 '18 19:09

Madlon


People also ask

Does Docker automatically open ports?

Published portsBy default, when you create or run a container using docker create or docker run , it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag.

Does restarting Docker restart all containers?

For a major version upgrade, one has to tear down all running containers. With a restart policy of always , however, the containers will be restarted after the docker daemon is restarted after the upgrade.

What happens on Docker restart?

Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Restart policies ensure that linked containers are started in the correct order. Docker recommends that you use restart policies, and avoid using process managers to start containers.


2 Answers

Try restarting your docker service after , sudo /etc/init.d/docker restart it should resolve the problem

like image 65
Vivek C Avatar answered Oct 17 '22 23:10

Vivek C


Normally if your docker container is starting automatically and allocating some port, you added by mistake the option --restart to start containers automatically.

So If after you restart the docker service, the docker-pr service allocates the port of some container, your container is starting automatically.

After starting the docker, to check if you have some container running use:

docker ps

To stop this container, we can use:

docker stop container_name

If you have more than one container, we can use:

docker stop $(docker ps -a -q)

Normally, if you have some container starting automatically, you set this using docker --restart we need to remove it from the auto restart.

To do this use the following command:

docker update --restart=no container_name

After this, you will able to restart your docker service and you will not found any container starting automatically.

like image 2
valdeci Avatar answered Oct 17 '22 23:10

valdeci