when I execute the docker command I get "invalid reference format" error - node.js

How can I fix this problem?
docker: invalid reference format.
I have executed this command:
docker run -d --rm -p 3000:8000 -env port=8000 --name feedback-app -v feedback:/app/feedback -v "c:/workspace/d/data-volumes-07-added-dockerignore/data-volumes-07-added-dockerignore:/app:ro" -v /app/node_modules -v /app/temp feedback-node:env

I had forgotten something in my command!
I changed -env to --env
docker run -d --rm -p 3000:8000 --env port=8000 --name feedback-app -v feedback:/app/feedback -v "c:/workspace/d/data-volumes-07-added-dockerignore/data-volumes-07-added-dockerignore:/app:ro" -v /app/node_modules -v /app/temp feedback-node:env

Related

Docker within Docker container not mapping .ssh volume

Im trying to map a volume from my main host machine, into a docker container, which then creates another docker container.
my first container is created as per the below:
docker run --rm -it \
-e JOB="release" \
-e LOG_FOLDER="$logDirectory" \
-v "$logDirectory":"$logDirectory" \
-e TEMP_FOLDER="$tempFolder" \
-v ~/.ssh:/root/.ssh \
-v "$tempFolder":"$tempFolder" \
-v /var/run/docker.sock:/var/run/docker.sock \
release
The above works great, and when I /bin/bash into this container I can see that the .ssh folder has mapped and is showing the contents from my host machine.
But then when I try to create ANOTHER docker container within this one, using the below:
docker run --rm -it \
-e JOB=summary \
-e TEMP_FOLDER="$TEMP_FOLDER" \
-v "$TEMP_FOLDER":"$TEMP_FOLDER" \
-v ~/.ssh:/root/.ssh \
-v /var/run/docker.sock:/var/run/docker.sock \
summary /bin/bash
The container is created with no issues, but the .ssh folder content hasn't been mapped. However the TEMP_FOLDER has been mapped correctly and is showing the content from the host machine, I dont know why the .ssh folder isn't doing the same?
Is there a permission problem?
Not sure why but the work around ive found is below, perhaps the root user was not the same across containers.
docker run --rm -it \
-e JOB="release" \
-e LOG_FOLDER="$logDirectory" \
-v "$logDirectory":"$logDirectory" \
-e TEMP_FOLDER="$tempFolder" \
-v ~/.ssh:/root/.ssh \
-v ~/.ssh:/home/user/.ssh \
-v /home/user/.ssh:/root/.ssh \
-v "$tempFolder":"$tempFolder" \
-v /var/run/docker.sock:/var/run/docker.sock \
release
docker run --rm -it \
-e JOB=summary \
-e TEMP_FOLDER="$TEMP_FOLDER" \
-v "$TEMP_FOLDER":"$TEMP_FOLDER" \
-v /home/user/.ssh:/root/.ssh \
-v /var/run/docker.sock:/var/run/docker.sock \
summary /bin/bash

Why am I unable to cd within a dockercontainer?

I would like to automatically execute tasks inside a docker container. The task that should be executed should be run inside a specific, mounted directory. To do this, I am using the this command:
docker run --rm -v /a/dir/on/my/host:/tmp some_container /bin/bash -c "cd /tmp/dir/inside/volume && echo \"$PWD\""
, followed by the actual task, which I omit, due to brevity.
PWD should give me /tmp/dir/inside/volume, but prints /a/dir/on/my/host. Why is that?
$PWD is expanded before you run your container. Use single quotes instead of double quotes to defer expansion. Also it's simpler to use --workdir or -w instead of cd .. && and subshell.
docker run --rm -v /a/dir/on/my/host:/tmp some_container /bin/bash -c 'cd /tmp/dir/inside/volume && echo "$PWD"'
or I suggest:
docker run --rm -v /a/dir/on/my/host:/tmp -w /tmp/dir/inside/volume /some_container pwd

Executing a command inside docker shows wrong $PATH

I am trying to run a bash command inside docker from host:
$ docker exec -it -u weiss apollo_dev /bin/bash -c "rosbag"
/bin/bash: rosbag: command not found
So I tried:
$ docker exec -it -u weiss apollo_dev /bin/bash -c "echo \$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
But when I run docker interactively:
$ docker exec -it -u weiss apollo_dev /bin/bash
weiss#docker$ echo $PATH
/usr/local/cuda-8.0/bin:/home/tmp/ros/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Any reason why I am getting different results for $PATH?
This path is most likely changed in your .bashrc file, and this file is not loaded when the shell is non interactive (see https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files)
So /bin/bash will load it, /bin/bash -c will not
Here you are getting de $PATH of your Host. Before you run the container the variable is replace for the host's $PATH.
$ docker exec -it -u weiss apollo_dev /bin/bash -c "echo \$PATH"
You need to pass the command without replace the variable, so when run the command in the container just invoke the $PATH variable.
$ docker exec -it -u weiss apollo_dev /bin/bash -c 'echo \$PATH'
Te 'apostrophe' is the key. Bye

setting up variables in alias is not working

I want my alias to pick up variables that I pass in commandLine:
For example, startdocker 004 should execute the following
docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar:004
(004 is the tag I am passing in commandLine).
I tried the following in my .bashrc (sourced after the change).
alias startdocker='function dockerStartTag(){ echo "docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1";};dockerStartTag'
when I run startdocker 004, It is not picking up 004.
It is empty and hence defaults to "latest" by docker.
what is the correct way to do it? what am I doing wrong?
Thanks
EDIT
I don't want to echo but execute the command.
The correct answer is provided below
There's no reason to put a function inside an alias. Just do
function startdocker(){ echo "docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1"; }
This now works on my system:
$ startdocker 004
docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: 004
And to actually run it, we just need:
function startdocker(){ docker run -d -t -p 8080:8080 -v /var/source:/source -P mydockerregistry:5000/foo/bar: $1; }

Linux expect spawn can not find file

I wrote a expect script named load_data.exp
#!/usr/bin/expect
spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm"
expect "Password:" {send "mysecretpassword"}
change access by
chmod +x load_data.exp
run it by
./load_data.exp
the file definitely exits, it gives me error
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
couldn't execute "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm": no such file or directory
while executing
"spawn "osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm""
(file "./load_data.exp" line 6)
osm2pgsql is installed and can be run directly in terminal the following sentence
osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
so there is a problem with spawn, I guess
As the error suggests, it's trying to find a program not called osm2pgsql, but one called osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm including all the spaces and dashes as part of the executable name. Remove the quotes from the spawn command:
spawn osm2pgsql -s -l -d postgres -W -U postgres -H localhost -P 5432 --hstore /absolute/path/to/bruges_belgium.osm
Try specifying absolute path to osm2pgsql (acquired by command 'which osm2pgsql')

Resources