0

Why does this command copy everything in the frontend/ directory to the docker container...

docker run -it --rm -d -p 8080:80 --name webserver -v $( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/frontend/:/var/www/icebear.se -v $( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/nginx/webserver.conf:/etc/nginx/sites-enabled/icebear.se webserver

... and this command is only copying the directory frontend/ without its content?

read -e mypath
docker run -it --rm -d -p 8080:80 --name webserver -v $mypath/frontend/:/var/www/icebear.se -v "$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"/nginx/webserver.conf:/etc/nginx/sites-available/icebear.se webserver

If i echo $( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P ) i get this /Users/gnusson/Documents/GitHub/dockerized-webserver

If i run my second command instead and echo $mypath i get this /Users/gnusson/Documents/GitHub/dockerized-webserver

Exact the same, but for some reason behaves different.

Gnusson
  • 305
  • 1
  • 2
  • 9
  • Sorry about that, I updated my question. In my code I have it like you suggested, i copied the wrong "version" of my code. There is something else thats not working, are the read -e mypath formatting it badly or so? – Gnusson Apr 07 '22 at 15:27
  • 1
    `set -x` is your friend; so is `declare -p mypath`. `echo` leaves out critical details; f/e, you can't see if there are carriage returns on the ends of your variables. – Charles Duffy Apr 07 '22 at 15:30
  • 1
    enable debugging (`set -xv`) and run both commands to see what's actually being passed to `docker`?; I'd also suggest updating the code so the 2nd `-v` is the same (2nd example wraps the subprocess call in double quotes - `-v "$( cd -- ...)"/nginx/`) ... probably not an issue in this case but wouldn't hurt to insure comparing apples to apples – markp-fuso Apr 07 '22 at 15:31
  • (with new enough versions of bash, you can use `echo "${mypath@Q}"` safely to get an unambiguous representation -- at least with echo in its default configuration -- but that requires 5.0) – Charles Duffy Apr 07 '22 at 15:31
  • (also, `echo $somevar` adds bugs of its own -- see [I just assigned a variable, but `echo $variable` shows something else!](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else)) – Charles Duffy Apr 07 '22 at 15:32
  • @CharlesDuffy, I am sorry for being such noob, but where should i use the `set -x` and `declare -p mypath`? – Gnusson Apr 07 '22 at 15:33
  • @Gnusson, `set -x` should come *before* the lines you want to see trace logs for (it turns logging on, `set +x` turns it back off). – Charles Duffy Apr 07 '22 at 15:33
  • @Gnusson, ...whereas `declare -p mypath` is a bash-specific way to ask the shell to show you what's currently in the variable `mypath`; you should use it anywhere you would otherwise use `echo "$mypath"`. (If it doesn't work, that implies maybe your shell is `sh` instead of `bash`). – Charles Duffy Apr 07 '22 at 15:34
  • @CharlesDuffy I have tried this but it does not work... I with set -x and declare -p mypath I can see anything thats wrong... – Gnusson Apr 07 '22 at 15:38
  • Please [edit] the logs into the question -- even if they don't show anything wrong, they might rule some things out. – Charles Duffy Apr 07 '22 at 15:40
  • 1
    Thanks for the help! Finally solved it... I copied the output from `set -x` in the two scenarios. Then pasted them in a text compare and saw that I copied my files to `sites-available` in one and `sites-enabled` on the other one... – Gnusson Apr 07 '22 at 15:43
  • Since your question turned out to be caused by a typo, consider deleting it. (See #2 in the "some questions are still off-topic" list at https://stackoverflow.com/help/on-topic) – Charles Duffy Apr 07 '22 at 16:17

0 Answers0