Custom Boot Action/Script


I am not super experienced with all the docker stuff yet so there might be a a simple way to do this from a container that I am unaware of.

But anyway what I am looking to do is have the system run this script on boot:
iw phy0 interface add wlan1 type managed 2>/dev/null

I am basically using a BBB with the wireless cape and the above line is how you enable the SoftAP on the wm1835mod so that you can have a wlan1 that can be used as a hotspot. Everything is working great as is in the system boots and brings up wlan0 itself using the resin-wifi connection settings and then after i call the line above i can start the hotspot using the resin-hotspot settings. The probably is i have to run the above command manually over the terminal right now.

Any advice would be greatly appreciated : )

Hey jcc273,

I took some time crafting a reply that provides what I think is the bare bones knowledge on Docker needed for you to confidently implement a solution to this need:

1. Dockerfile

If you take a look at the repository of your project, assuming you cloned it from one of our getting-started repo’s [1], you’ll see a file named:


A Dockerfile [2] is a file used by the container engine to build the OS image which will run. A Dockerfile can copy files in from the build environment (in this case, your project folder), can configure the machine in various ways, install packages, etc…

2. The boot process inside the container

One of the directives a Dockerfile can contain to define the image is the “CMD” directive [3]. This directive tells the container how it should boot. At boot, a linux system wants to run a command which will have PID 1 and spawn other processes. In a full OS, this is called the “init system” [4].

In a docker container, a regular process, like a bash script, or a binary of some other kind (node, apache, etc., etc.) functions as the root of the linux process tree with PID 1. All other process that will run in the container must be spawned by that process.

You probably currently have a “CMD” directive in your Dockerfile. Let’s say your Dockerfile has CMD ["node", "server.js"] (replace mentally with whatever you have). The only thing to do is to change it so that it points to a script: CMD [""], and make sure that “” runs the commands you need before running “node server.js”. You would need to make sure that is added to the working directory on the image.

So, if your project had, at the top level, the two files “” and “Dockerfile”, your Dockerfile would end like this:

# add to workdir
# run
CMD [""]

and would be something like:


iw phy0 interface add wlan1 type managed
node index.js

(I removed the pipe of stderr to dev/null, since if this command fails, it’ll be nice to be able to see that in the logs).

4. Systemd is awesome

There is a more robust method to specify system boot-time processes, in case things get a little too complicated and isn’t cutting it. You can to specify “systemd unit files”. This requires your machine to be running the systemd init system. Our debian- and fedora-based images can be configured to run systemd init by adding


to your Dockerfile.

You would create a file “setup-wlan1.service” with the following contents:

Description=add wlan1 to phy0

ExecStart=iw phy0 interface add wlan1 type managed


You would add this service file to your image and enable the service, in your Dockerfile:

ADD setup-wlan1.service /etc/systemd/system
RUN systemctl enable setup-wlan1

I hope this has been a helpful guide!

– dt-rush

[1] A “getting started” example project -
[2] Docker documentation, “Dockerfile reference” -
[3] Docker documentation, “Dockerfile reference :: CMD” -
[4] Wikipedia - “Init”
[5] Balena documentation, “Balena base images :: Init system” -