Can I run a shell script inside of a docker container with the help of a docker compose file?

Hello everyone I am kind of new in this theme I am searing to run a shell script inside a docker container or even tried to find to run debian 11 inside a docker container with a docker compose yet unseucessfull or I am to stupid to find it and I don’t know what to do can anyone help me?

My goal is:
have wget preinstalled inside the container
Run SH script
open ports with the following ranges: 5060-5090 16384-32768
I am trying it to do as a project but I can’t find a resolution thanks in advance if anyone can help me

Docker version: Docker version 23.0.4, build f480fb1
Docker Compose version v2.17.2
OS: Debian 11

I am by no means an expert, but wouldn’t you be better building your own container for that?

i.e.

  • Create a new dockerfile
    • Select your base image
    • Install wget
    • Run your script

Build this, then you can run that with docker run or docker compose and open the ports you need (-p 5060-5090:5060-5090).

I used this same process to run a PowerShell script that runs and parses the output from an ipmi tool and the dockerfile is only ~15 lines. The build process is well documented if you have a search around.

How do I create/use a docker file? because well I only used docker compose files
Edit: and I use traefik and the script makes a web server so I wanted it to run through traefik

Assuming I’m allowed to post an outside link; have a look here:

There are many other guides but this is the first I found with a quick search.
It is pretty straightforward; if I can do it then anyone can :grinning:

1 Like

Thanks will read it ^-^

As long as it is on topic: of course!

Well I tried it but I only receive error 2 :confused: pls help me xD

C:\Users\Admin\Documents\Dockerized\apache2>docker build -t tara/fusionpbx .                                                                                                                                                                 [+] Building 15.0s (5/5) FINISHED                                                                                                                                                                                                             => [internal] load build definition from Dockerfile                                                                                                                                                                                    0.0s  => => transferring dockerfile: 371B                                                                                                                                                                                                    0.0s  => [internal] load .dockerignore                                                                                                                                                                                                       0.0s  => => transferring context: 2B                                                                                                                                                                                                         0.0s  => [internal] load metadata for docker.io/library/debian:11                                                                                                                                                                            0.5s  => CACHED [1/2] FROM docker.io/library/debian:11@sha256:0a78ed641b76252739e28ebbbe8cdbd80dc367fba4502565ca839e5803cfd86e                                                                                                               0.0s  => ERROR [2/2] RUN apt-get update &&     apt-get install -y wget perl &&     apt-get clean     wget -O - https://raw.githubusercontent.com/fusionpbx/fusionpbx-install.sh/master/debian/pre-install.sh | sh; cd /usr/src/fusionpbx-i  14.3s ------                                                                                                                                                                                                                                        > [2/2] RUN apt-get update &&     apt-get install -y wget perl &&     apt-get clean     wget -O - https://raw.githubusercontent.com/fusionpbx/fusionpbx-install.sh/master/debian/pre-install.sh | sh; cd /usr/src/fusionpbx-install.sh/debian && ./install.sh:                                                                                                                                                                                                                           #5 0.520 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]                                                                                                                                                                      #5 0.629 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]                                                                                                                                                   #5 0.720 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]                                                                                                                                                             #5 0.821 Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]                                                                                                                                                           #5 5.944 Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [237 kB]                                                                                                                                          #5 6.076 Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [14.6 kB]                                                                                                                                                   #5 6.673 Fetched 8643 kB in 6s (1367 kB/s)                                                                                                                                                                                                   #5 6.673 Reading package lists...                                                                                                                                                                                                            #5 7.135 Reading package lists...                                                                                                                                                                                                            #5 7.572 Building dependency tree...                                                                                                                                                                                                         #5 7.702 Reading state information...                                                                                                                                                                                                        #5 7.910 The following additional packages will be installed:                                                                                                                                                                                #5 7.911   ca-certificates libgdbm-compat4 libgdbm6 libperl5.32 libpsl5 netbase openssl                                                                                                                                                      #5 7.912   perl-modules-5.32 publicsuffix                                                                                                                                                                                                    #5 7.914 Suggested packages:                                                                                                                                                                                                                 #5 7.914   gdbm-l10n sensible-utils perl-doc libterm-readline-gnu-perl                                                                                                                                                                       #5 7.914   | libterm-readline-perl-perl make libtap-harness-archive-perl                                                                                                                                                                     #5 7.994 The following NEW packages will be installed:                                                                                                                                                                                       #5 7.995   ca-certificates libgdbm-compat4 libgdbm6 libperl5.32 libpsl5 netbase openssl                                                                                                                                                      #5 7.995   perl perl-modules-5.32 publicsuffix wget                                                                                                                                                                                          #5 8.074 0 upgraded, 11 newly installed, 0 to remove and 11 not upgraded.                                                                                                                                                                    #5 8.074 Need to get 9512 kB of archives.                                                                                                                                                                                                    #5 8.074 After this operation, 53.3 MB of additional disk space will be used.                                                                                                                                                                #5 8.074 Get:1 http://deb.debian.org/debian bullseye/main amd64 perl-modules-5.32 all 5.32.1-4+deb11u2 [2823 kB]                                                                                                                             #5 8.579 Get:2 http://deb.debian.org/debian bullseye/main amd64 libgdbm6 amd64 1.19-2 [64.9 kB]                                                                                                                                              #5 8.673 Get:3 http://deb.debian.org/debian bullseye/main amd64 libgdbm-compat4 amd64 1.19-2 [44.7 kB]                                                                                                                                       #5 8.759 Get:4 http://deb.debian.org/debian bullseye/main amd64 libperl5.32 amd64 5.32.1-4+deb11u2 [4106 kB]                                                                                                                                 #5 9.420 Get:5 http://deb.debian.org/debian bullseye/main amd64 perl amd64 5.32.1-4+deb11u2 [293 kB]                                                                                                                                         #5 9.569 Get:6 http://deb.debian.org/debian bullseye/main amd64 netbase all 6.3 [19.9 kB]                                                                                                                                                    #5 9.635 Get:7 http://deb.debian.org/debian bullseye/main amd64 openssl amd64 1.1.1n-0+deb11u4 [853 kB]                                                                                                                                      #5 9.963 Get:8 http://deb.debian.org/debian bullseye/main amd64 ca-certificates all 20210119 [158 kB]                                                                                                                                        #5 10.09 Get:9 http://deb.debian.org/debian bullseye/main amd64 libpsl5 amd64 0.21.0-1.2 [57.3 kB]                                                                                                                                           #5 10.18 Get:10 http://deb.debian.org/debian bullseye/main amd64 wget amd64 1.21-1+deb11u1 [964 kB]                                                                                                                                          #5 10.58 Get:11 http://deb.debian.org/debian bullseye/main amd64 publicsuffix all 20220811.1734-0+deb11u1 [127 kB]                                                                                                                           #5 10.73 debconf: delaying package configuration, since apt-utils is not installed                                                                                                                                                           #5 10.76 Fetched 9512 kB in 3s (3614 kB/s)                                                                                                                                                                                                   #5 10.77 Selecting previously unselected package perl-modules-5.32.                                                                                                                                                                          (Reading database ... 6664 files and directories currently installed.)                                                                                                                                                                       #5 10.78 Preparing to unpack .../00-perl-modules-5.32_5.32.1-4+deb11u2_all.deb ...                                                                                                                                                           #5 10.78 Unpacking perl-modules-5.32 (5.32.1-4+deb11u2) ...                                                                                                                                                                                  #5 11.14 Selecting previously unselected package libgdbm6:amd64.                                                                                                                                                                             #5 11.14 Preparing to unpack .../01-libgdbm6_1.19-2_amd64.deb ...                                                                                                                                                                            #5 11.15 Unpacking libgdbm6:amd64 (1.19-2) ...                                                                                                                                                                                               #5 11.19 Selecting previously unselected package libgdbm-compat4:amd64.                                                                                                                                                                      #5 11.19 Preparing to unpack .../02-libgdbm-compat4_1.19-2_amd64.deb ...                                                                                                                                                                     #5 11.19 Unpacking libgdbm-compat4:amd64 (1.19-2) ...                                                                                                                                                                                        #5 11.23 Selecting previously unselected package libperl5.32:amd64.                                                                                                                                                                          #5 11.23 Preparing to unpack .../03-libperl5.32_5.32.1-4+deb11u2_amd64.deb ...                                                                                                                                                               #5 11.24 Unpacking libperl5.32:amd64 (5.32.1-4+deb11u2) ...                                                                                                                                                                                  #5 11.66 Selecting previously unselected package perl.                                                                                                                                                                                       #5 11.66 Preparing to unpack .../04-perl_5.32.1-4+deb11u2_amd64.deb ...                                                                                                                                                                      #5 11.67 Unpacking perl (5.32.1-4+deb11u2) ...                                                                                                                                                                                               #5 11.72 Selecting previously unselected package netbase.                                                                                                                                                                                    #5 11.73 Preparing to unpack .../05-netbase_6.3_all.deb ...                                                                                                                                                                                  #5 11.73 Unpacking netbase (6.3) ...                                                                                                                                                                                                         #5 11.76 Selecting previously unselected package openssl.                                                                                                                                                                                    #5 11.76 Preparing to unpack .../06-openssl_1.1.1n-0+deb11u4_amd64.deb ...                                                                                                                                                                   #5 11.77 Unpacking openssl (1.1.1n-0+deb11u4) ...                                                                                                                                                                                            #5 11.86 Selecting previously unselected package ca-certificates.                                                                                                                                                                            #5 11.86 Preparing to unpack .../07-ca-certificates_20210119_all.deb ...                                                                                                                                                                     #5 11.86 Unpacking ca-certificates (20210119) ...                                                                                                                                                                                            #5 11.92 Selecting previously unselected package libpsl5:amd64.                                                                                                                                                                              #5 11.92 Preparing to unpack .../08-libpsl5_0.21.0-1.2_amd64.deb ...                                                                                                                                                                         #5 11.92 Unpacking libpsl5:amd64 (0.21.0-1.2) ...                                                                                                                                                                                            #5 11.96 Selecting previously unselected package wget.                                                                                                                                                                                       #5 11.96 Preparing to unpack .../09-wget_1.21-1+deb11u1_amd64.deb ...                                                                                                                                                                        #5 11.96 Unpacking wget (1.21-1+deb11u1) ...                                                                                                                                                                                                 #5 12.06 Selecting previously unselected package publicsuffix.                                                                                                                                                                               #5 12.06 Preparing to unpack .../10-publicsuffix_20220811.1734-0+deb11u1_all.deb ...                                                                                                                                                         #5 12.06 Unpacking publicsuffix (20220811.1734-0+deb11u1) ...                                                                                                                                                                                #5 12.11 Setting up libpsl5:amd64 (0.21.0-1.2) ...                                                                                                                                                                                           #5 12.12 Setting up wget (1.21-1+deb11u1) ...                                                                                                                                                                                                #5 12.14 Setting up perl-modules-5.32 (5.32.1-4+deb11u2) ...                                                                                                                                                                                 #5 12.15 Setting up netbase (6.3) ...                                                                                                                                                                                                        #5 12.18 Setting up openssl (1.1.1n-0+deb11u4) ...                                                                                                                                                                                           #5 12.20 Setting up publicsuffix (20220811.1734-0+deb11u1) ...                                                                                                                                                                               #5 12.21 Setting up libgdbm6:amd64 (1.19-2) ...                                                                                                                                                                                              #5 12.22 Setting up ca-certificates (20210119) ...                                                                                                                                                                                           #5 12.29 debconf: unable to initialize frontend: Dialog                                                                                                                                                                                      #5 12.29 debconf: (TERM is not set, so the dialog frontend is not usable.)                                                                                                                                                                   #5 12.29 debconf: falling back to frontend: Readline                                                                                                                                                                                         #5 12.56 Updating certificates in /etc/ssl/certs...                                                                                                                                                                                          #5 12.99 129 added, 0 removed; done.                                                                                                                                                                                                         #5 13.02 Setting up libgdbm-compat4:amd64 (1.19-2) ...                                                                                                                                                                                       #5 13.03 Setting up libperl5.32:amd64 (5.32.1-4+deb11u2) ...                                                                                                                                                                                 #5 13.04 Setting up perl (5.32.1-4+deb11u2) ...                                                                                                                                                                                              #5 13.06 Processing triggers for libc-bin (2.31-13+deb11u5) ...                                                                                                                                                                              #5 13.08 Processing triggers for ca-certificates (20210119) ...                                                                                                                                                                              #5 13.08 Updating certificates in /etc/ssl/certs...                                                                                                                                                                                          #5 13.40 0 added, 0 removed; done.                                                                                                                                                                                                           #5 13.40 Running hooks in /etc/ca-certificates/update.d...                                                                                                                                                                                   #5 13.41 done.                                                                                                                                                                                                                               #5 13.43 E: Command line option 'O' [from -O] is not understood in combination with the other options.                                                                                                                                       #5 13.43 /bin/sh: 1: cd: can't cd to /usr/src/fusionpbx-install.sh/debian                                                                                                                                                                    ------                                                                                                                                                                                                                                       executor failed running [/bin/sh -c apt-get update &&     apt-get install -y wget perl &&     apt-get clean     wget -O - https://raw.githubusercontent.com/fusionpbx/fusionpbx-install.sh/master/debian/pre-install.sh | sh; cd /usr/src/fusionpbx-install.sh/debian && ./install.sh]: exit code: 2                                                                                                                                                                                                                                                                                                                                                                                                                                   C:\Users\Admin\Documents\Dockerized\apache2>    

Dockerfile Code:

FROM debian:11

RUN apt-get update && \
    apt-get install -y wget perl && \
    apt-get clean \
    wget -O - https://raw.githubusercontent.com/fusionpbx/fusionpbx-install.sh/master/debian/pre-install.sh | sh; \
    cd /usr/src/fusionpbx-install.sh/debian && ./install.sh

EXPOSE 16384-32768 5060-5090 80 443

CMD ["fusionpbx"]

I am trying to isolate the FusionPBX

nevermind I fixed it

FROM debian:11

RUN apt-get update && \
    apt-get install -y wget perl && \
    apt-get clean
RUN wget -O - https://raw.githubusercontent.com/fusionpbx/fusionpbx-install.sh/master/debian/pre-install.sh | sh; \
    cd /usr/src/fusionpbx-install.sh/debian && ./install.sh

EXPOSE 16384-32768 5060-5090 80 443

CMD ["fusionpbx"]

Edit2: after 25 min I get this message bruuuu

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "fusionpbx": executable file not found in $PATH: unknown.

The error message is clear about the problem: the command is not found in the $PATH variable.

You either need to add the path where fusionpbx is located to the PATH variable (ENV PATH=$PATH:/wherever/fusionpbx/is/located (the folder path the file is inside, not the file path!)) or you need to use the absolute path to fusionpbx in the CMD instruction.

do I need to add it to the dockerfile? if yes REEEEEEEEEEEEEEE cause it took 24 min to generate

wait a second I just noticed it is the command I just entered it is not a real command because for so it is a service what starts when the Server starts

I assume you mean it starts as a systemd service. Well, this might work on the host, but it definitely will not inside a container. By default, base images have no systemd, and it is actually not desired to have it.

The ENTRYPOINT and/or CMD instruction must declare the command that either starts the service as foreground service itself, or calls a shell script that does it.

Well it installs: lsb-release systemd systemd-sysv ca-certificates dialog nano net-tools snmpd iptables sngrep FusionPBX PHP Nginx FreeSwitch F2B Postgrep

I have no idea why your last response is a list of packages… What am I supposed to do with it? And how does it relate to my previous response?