Docker - Rebooting raspberry pi host from within docker containerHow is Docker different from a virtual machine?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersWhere are Docker images stored on the host machine?Copying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?Docker Volumes not mounted after host reboot
Is Prophet from Facebook any different from a linear regression?
<schwitz>, <zwinker> etc. Does German always use 2nd Person Singular Imperative verbs for emoticons? If so, why?
Why does Hellboy file down his horns?
Assign media item to sitecore item using powershell script
Robbers: The Hidden OEIS Substring
What are the steps/action plan to introduce Test Automation in a company?
Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?
When did the Roman Empire fall according to contemporaries?
How do I take a fraction to a negative power?
Was the Ford Model T black because of the speed black paint dries?
How do Windows version numbers work?
Are there any double stars that I can actually see orbit each other?
Are neural networks prone to catastrophic forgetting?
How can I deal with a player trying to insert real-world mythology into my homebrew setting?
Crowbar circuit causes unexpected behavior for op amp circuit
Reverse the word order in string, without reversing the words
Why can't supermassive black holes merge? (or can they?)
Is it possible for thermophilic viruses to infect humans?
Cubic programming and beyond?
How can one write good dialogue in a story without sounding wooden?
Were there any new Pokémon introduced in the movie Pokémon: Detective Pikachu?
Are randomly-generated passwords starting with "a" less secure?
Is Trump personally blocking people on Twitter?
Is this floating-point optimization allowed?
Docker - Rebooting raspberry pi host from within docker container
How is Docker different from a virtual machine?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersWhere are Docker images stored on the host machine?Copying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repositoryFrom inside of a Docker container, how do I connect to the localhost of the machine?Docker Volumes not mounted after host reboot
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a python application that's meant to be run on a raspberry pi. I've created a docker-compose file to set it up, and my entry point happens to be a shell script that checks various things on the host such as:
- Making sure SPI is enabled, if it is not then enabling it by accessing /boot/config.txt and writing to it.
- Installing and enabling the watchdog service.
- Running my docker container automatically on reboot by writing it into /etc/rc.local (although I am considering replacing this with the restart: always or unless-stopped flag from the docker-compose file)
The problem is, if I enable SPI, the raspberry pi needs to reboot to set it up (not quite sure why), but when my shell script reaches the sudo reboot command from within the docker container, I get the following error:
Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
I understand that it's probably trying to find dbus and the init daemon within the docker container but they don't exist. How do I give my container access to these resources? Do I need to mount another volume? This is my docker-compose.yml file:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
#image: "arkfreestyle/fg:v1.8"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
FG is my python application with the entry point docker-entrypoint.sh which looks like:
#!/bin/sh
if [ ! -f /home/pi/.initialized ]; then
echo "Initializing..."
# Turn spi on
if grep -Fxq "dtparam=spi=on
dtparam=watchdog=on" /boot/config.txt
then
echo "nSPI is already enabled"
echo "Creating .initialized"
# Create .initialized hidden file
touch /home/pi/.initialized
echo "Starting application..."
sudo python3 __main__.py -debug
else
### Enable SPI ###
fi
fi
### Create .initialized file ###
echo "Rebooting in ten seconds..."
sleep 10
sudo reboot # This line results in the error
else
echo "Initialized already!"
sudo python3 __main__.py -debug
fi
The privileged option already gives my container access to the GPIO, I imagined it would give me access to reboot as well, however it seems that is not the case. Please let me know what I need to do to be able to reboot.
linux docker raspberry-pi docker-compose
add a comment |
I have a python application that's meant to be run on a raspberry pi. I've created a docker-compose file to set it up, and my entry point happens to be a shell script that checks various things on the host such as:
- Making sure SPI is enabled, if it is not then enabling it by accessing /boot/config.txt and writing to it.
- Installing and enabling the watchdog service.
- Running my docker container automatically on reboot by writing it into /etc/rc.local (although I am considering replacing this with the restart: always or unless-stopped flag from the docker-compose file)
The problem is, if I enable SPI, the raspberry pi needs to reboot to set it up (not quite sure why), but when my shell script reaches the sudo reboot command from within the docker container, I get the following error:
Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
I understand that it's probably trying to find dbus and the init daemon within the docker container but they don't exist. How do I give my container access to these resources? Do I need to mount another volume? This is my docker-compose.yml file:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
#image: "arkfreestyle/fg:v1.8"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
FG is my python application with the entry point docker-entrypoint.sh which looks like:
#!/bin/sh
if [ ! -f /home/pi/.initialized ]; then
echo "Initializing..."
# Turn spi on
if grep -Fxq "dtparam=spi=on
dtparam=watchdog=on" /boot/config.txt
then
echo "nSPI is already enabled"
echo "Creating .initialized"
# Create .initialized hidden file
touch /home/pi/.initialized
echo "Starting application..."
sudo python3 __main__.py -debug
else
### Enable SPI ###
fi
fi
### Create .initialized file ###
echo "Rebooting in ten seconds..."
sleep 10
sudo reboot # This line results in the error
else
echo "Initialized already!"
sudo python3 __main__.py -debug
fi
The privileged option already gives my container access to the GPIO, I imagined it would give me access to reboot as well, however it seems that is not the case. Please let me know what I need to do to be able to reboot.
linux docker raspberry-pi docker-compose
add a comment |
I have a python application that's meant to be run on a raspberry pi. I've created a docker-compose file to set it up, and my entry point happens to be a shell script that checks various things on the host such as:
- Making sure SPI is enabled, if it is not then enabling it by accessing /boot/config.txt and writing to it.
- Installing and enabling the watchdog service.
- Running my docker container automatically on reboot by writing it into /etc/rc.local (although I am considering replacing this with the restart: always or unless-stopped flag from the docker-compose file)
The problem is, if I enable SPI, the raspberry pi needs to reboot to set it up (not quite sure why), but when my shell script reaches the sudo reboot command from within the docker container, I get the following error:
Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
I understand that it's probably trying to find dbus and the init daemon within the docker container but they don't exist. How do I give my container access to these resources? Do I need to mount another volume? This is my docker-compose.yml file:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
#image: "arkfreestyle/fg:v1.8"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
FG is my python application with the entry point docker-entrypoint.sh which looks like:
#!/bin/sh
if [ ! -f /home/pi/.initialized ]; then
echo "Initializing..."
# Turn spi on
if grep -Fxq "dtparam=spi=on
dtparam=watchdog=on" /boot/config.txt
then
echo "nSPI is already enabled"
echo "Creating .initialized"
# Create .initialized hidden file
touch /home/pi/.initialized
echo "Starting application..."
sudo python3 __main__.py -debug
else
### Enable SPI ###
fi
fi
### Create .initialized file ###
echo "Rebooting in ten seconds..."
sleep 10
sudo reboot # This line results in the error
else
echo "Initialized already!"
sudo python3 __main__.py -debug
fi
The privileged option already gives my container access to the GPIO, I imagined it would give me access to reboot as well, however it seems that is not the case. Please let me know what I need to do to be able to reboot.
linux docker raspberry-pi docker-compose
I have a python application that's meant to be run on a raspberry pi. I've created a docker-compose file to set it up, and my entry point happens to be a shell script that checks various things on the host such as:
- Making sure SPI is enabled, if it is not then enabling it by accessing /boot/config.txt and writing to it.
- Installing and enabling the watchdog service.
- Running my docker container automatically on reboot by writing it into /etc/rc.local (although I am considering replacing this with the restart: always or unless-stopped flag from the docker-compose file)
The problem is, if I enable SPI, the raspberry pi needs to reboot to set it up (not quite sure why), but when my shell script reaches the sudo reboot command from within the docker container, I get the following error:
Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
I understand that it's probably trying to find dbus and the init daemon within the docker container but they don't exist. How do I give my container access to these resources? Do I need to mount another volume? This is my docker-compose.yml file:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
#image: "arkfreestyle/fg:v1.8"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
FG is my python application with the entry point docker-entrypoint.sh which looks like:
#!/bin/sh
if [ ! -f /home/pi/.initialized ]; then
echo "Initializing..."
# Turn spi on
if grep -Fxq "dtparam=spi=on
dtparam=watchdog=on" /boot/config.txt
then
echo "nSPI is already enabled"
echo "Creating .initialized"
# Create .initialized hidden file
touch /home/pi/.initialized
echo "Starting application..."
sudo python3 __main__.py -debug
else
### Enable SPI ###
fi
fi
### Create .initialized file ###
echo "Rebooting in ten seconds..."
sleep 10
sudo reboot # This line results in the error
else
echo "Initialized already!"
sudo python3 __main__.py -debug
fi
The privileged option already gives my container access to the GPIO, I imagined it would give me access to reboot as well, however it seems that is not the case. Please let me know what I need to do to be able to reboot.
linux docker raspberry-pi docker-compose
linux docker raspberry-pi docker-compose
edited Mar 26 at 11:06
AbdurRehman Khan
asked Mar 26 at 4:35
AbdurRehman KhanAbdurRehman Khan
1236 bronze badges
1236 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
My first guess is that you simply need to expose /run/dbus
and /run/systemd
to your container, as in:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd ...
But while that is necessary, it isn't sufficient; with just those two bind mounts, attempting to interact with the host systemd from inside the container results in:
[root@631fff40f09c /]# reboot
Failed to connect to bus: No data available
Failed to talk to init daemon.
It turns out that the in order for this to work, the container must be running in the host's global PID namespace, which means we need:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd --pid=host ...
With this in place, running reboot
inside the container successfully reboots the host.
In a docker-compose.yml
, that would look something like:
FG:
privileged: true
network_mode: "host"
pid: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
- "/run/dbus:/run/dbus"
- "/run/systemd:/run/systemd"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using--pid=host
. Glad it turned out to be simpler for you!
– larsks
Mar 26 at 14:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349923%2fdocker-rebooting-raspberry-pi-host-from-within-docker-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
My first guess is that you simply need to expose /run/dbus
and /run/systemd
to your container, as in:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd ...
But while that is necessary, it isn't sufficient; with just those two bind mounts, attempting to interact with the host systemd from inside the container results in:
[root@631fff40f09c /]# reboot
Failed to connect to bus: No data available
Failed to talk to init daemon.
It turns out that the in order for this to work, the container must be running in the host's global PID namespace, which means we need:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd --pid=host ...
With this in place, running reboot
inside the container successfully reboots the host.
In a docker-compose.yml
, that would look something like:
FG:
privileged: true
network_mode: "host"
pid: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
- "/run/dbus:/run/dbus"
- "/run/systemd:/run/systemd"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using--pid=host
. Glad it turned out to be simpler for you!
– larsks
Mar 26 at 14:08
add a comment |
My first guess is that you simply need to expose /run/dbus
and /run/systemd
to your container, as in:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd ...
But while that is necessary, it isn't sufficient; with just those two bind mounts, attempting to interact with the host systemd from inside the container results in:
[root@631fff40f09c /]# reboot
Failed to connect to bus: No data available
Failed to talk to init daemon.
It turns out that the in order for this to work, the container must be running in the host's global PID namespace, which means we need:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd --pid=host ...
With this in place, running reboot
inside the container successfully reboots the host.
In a docker-compose.yml
, that would look something like:
FG:
privileged: true
network_mode: "host"
pid: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
- "/run/dbus:/run/dbus"
- "/run/systemd:/run/systemd"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using--pid=host
. Glad it turned out to be simpler for you!
– larsks
Mar 26 at 14:08
add a comment |
My first guess is that you simply need to expose /run/dbus
and /run/systemd
to your container, as in:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd ...
But while that is necessary, it isn't sufficient; with just those two bind mounts, attempting to interact with the host systemd from inside the container results in:
[root@631fff40f09c /]# reboot
Failed to connect to bus: No data available
Failed to talk to init daemon.
It turns out that the in order for this to work, the container must be running in the host's global PID namespace, which means we need:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd --pid=host ...
With this in place, running reboot
inside the container successfully reboots the host.
In a docker-compose.yml
, that would look something like:
FG:
privileged: true
network_mode: "host"
pid: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
- "/run/dbus:/run/dbus"
- "/run/systemd:/run/systemd"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
My first guess is that you simply need to expose /run/dbus
and /run/systemd
to your container, as in:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd ...
But while that is necessary, it isn't sufficient; with just those two bind mounts, attempting to interact with the host systemd from inside the container results in:
[root@631fff40f09c /]# reboot
Failed to connect to bus: No data available
Failed to talk to init daemon.
It turns out that the in order for this to work, the container must be running in the host's global PID namespace, which means we need:
docker run -v /run/dbus:/run/dbus -v /run/systemd:/run/systemd --pid=host ...
With this in place, running reboot
inside the container successfully reboots the host.
In a docker-compose.yml
, that would look something like:
FG:
privileged: true
network_mode: "host"
pid: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
- "/run/dbus:/run/dbus"
- "/run/systemd:/run/systemd"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
answered Mar 26 at 12:39
larskslarsks
131k21 gold badges216 silver badges218 bronze badges
131k21 gold badges216 silver badges218 bronze badges
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using--pid=host
. Glad it turned out to be simpler for you!
– larsks
Mar 26 at 14:08
add a comment |
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using--pid=host
. Glad it turned out to be simpler for you!
– larsks
Mar 26 at 14:08
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Hey thank you so much for your help! It turns out, just mounting /run/dbus was enough, and my container successfully rebooted the host :) I am curious as to why it worked without using the host's pid though, could it be that --net=host or --privileged cover that?
– AbdurRehman Khan
Mar 26 at 13:06
Not sure. I couldn't get it to work w/o using
--pid=host
. Glad it turned out to be simpler for you!– larsks
Mar 26 at 14:08
Not sure. I couldn't get it to work w/o using
--pid=host
. Glad it turned out to be simpler for you!– larsks
Mar 26 at 14:08
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349923%2fdocker-rebooting-raspberry-pi-host-from-within-docker-container%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown