Basics Dockerfile


Recommended Posts

Hi, as i started to create a own docker may some basic questions as i didnt came further yet ...

 

sample, if i want to use a variable in the run command wich i then can configure, how would that look like in the dockerfile

 

sample from Dockerfile

 

# port command
CMD ["-port=34400"]

 

now i tried with entries like

 

ENV webport

CMD ["-port=$webport"]

 

or

 

ARG ...

 

i guess its pretty basic but after reading several things i really dont get a clue ... ;)

 

next step would be to add stuff like if, then ... but first it would be nice for this basic help

 

thanks ahead

Link to comment
21 minutes ago, alturismo said:

Hi, as i started to create a own docker may some basic questions as i didnt came further yet ...

 

sample, if i want to use a variable in the run command wich i then can configure, how would that look like in the dockerfile

 

sample from Dockerfile

 

# port command
CMD ["-port=34400"]

 

now i tried with entries like

 

ENV webport

CMD ["-port=$webport"]

 

or

 

ARG ...

 

i guess its pretty basic but after reading several things i really dont get a clue ... ;)

 

next step would be to add stuff like if, then ... but first it would be nice for this basic help

 

thanks ahead

You shouldn't set variables in the Dockerfile itself as a general rule, variables come into play at the runtime stage not the build stage.

 

Might be helpful if you linked a Github repo or something, 'cos I'm not entirely clear what you're trying to do.

Link to comment
23 minutes ago, CHBMB said:

You shouldn't set variables in the Dockerfile itself as a general rule, variables come into play at the runtime stage not the build stage.

 

Might be helpful if you linked a Github repo or something, 'cos I'm not entirely clear what you're trying to do.

sure pretty simple, i try learning a little about building docker

 

sample

 

https://github.com/alturismo/xTeveTest/blob/master/Dockerfile <- working nuttom command port 34400

 

as you see i run the app and the port in docker hardcoded, now i d like to make the port configurable through the webgui,

so my start was to make it variable

 

so i could set something in unraid gui ...

 

sample

image.thumb.png.e9cc6fe44a985cb43059d633e09d324a.png

 

as mentioned, 1st docker, 1st tests ... i tried some stiff with ENV and ARG but never came to an result ;)

Link to comment

OK, you're getting confused between what you do in docker versus what you do in the Unraid webgui.

 

You add a port not a variable when you want to add a port to a Unraid template.  Set the container port to whatever the container port is, then change the host port to whatever you want it to be.

Link to comment

g morning, well, this was just an sample with a port

 

in this case this docker runs in host mode so port setting is obsolete ;) 

 

next step would be to config a subdirectory etc ... thats why i would like to know if i can set a variable to the CMD argue,

or is this always hardcoded ?

cause when i add dockers from apps here i also often can add variables etc wich are then used on docker run

Link to comment
16 hours ago, alturismo said:

g morning, well, this was just an sample with a port

 

in this case this docker runs in host mode so port setting is obsolete ;) 

 

next step would be to config a subdirectory etc ... thats why i would like to know if i can set a variable to the CMD argue,

or is this always hardcoded ?

cause when i add dockers from apps here i also often can add variables etc wich are then used on docker run

You're probably better looking at examples of how it's done. 

 

Dockerfile = uncustomised build that will be the same for everyone.

Init stage = Where customisation happens, copying/linking stuff to persistent storage, ingesting environmental variables to change the way the container runs or functions.

  • Upvote 1
Link to comment

may another question with a different approach

 

i tried now an startup script (entrypoint.sh) to get my execution(s) customizable

my goal is a config file wich then is used for executions

my problem seems to be the loop and detaching the app from terminal so it ll kill the app after the loop is done, while if theres no config file its working ...

 

thanks ahead for an tip

 

sample

 

config.txt

-port="34400" -debug="0"
-config="/root/.xteve/test/" -port="34401" -debug="2"

 

entrypoint.sh

#!/bin/sh

if [ -f "/root/.xteve/custom.txt" ]; then
    echo "Custom config found"

    file="/root/.xteve/custom.txt"
    while read -r line
    do
    if ! [[ ${line:0:1} = \# ]] ; then
        echo "Starting xteve with "$line""
        ./xteve/xteve "$line"                         ### << NOT working, gets executedm then stops ... docker dead ;)
    fi
    done <"$file"
    echo "all custom started"
else
    echo "no custom config, starting default"
    ./xteve/xteve -port="34400" -debug="0"       ### << working
fi

Edited by alturismo
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.