Using Docker For Mac, fish shell, macOS 10.11
I am trying to run the following command: docker run -d -it --name=my-app-container -v $(pwd):/app -p 3000:3000 myapp
I get the following error:
$(...) is not supported. In fish, please use '(pwd)'.
fish: docker run -d -it --name=my-app-container -v $(pwd):/app -p 3000:3000 myapp
Been reading through repos and SO answers but cant get this to work. Any ideas? Thank you.
The equivalent of bash $(command) in fish is just (command)
So all you need to do is remove the dollar sign.
docker run -d -it --name=my-app-cont -v (pwd):/app -p 3000:3000 myapp
Following #user2915097 's suggestion, seems like this doesn't throw an error....docker run -d -it --name=my-app-cont -v $PWD:/app -p 3000:3000 myapp. So switching $(pwd) to $PWD gets past this error.
Related
When I install something like nmap(even from APT), I cant get it to execute correctly, so I like to go the container route. Instead of typing:
docker run --rm -it instrumentisto/nmap -A -T4 scanme.nmap.org
I figured maybe I could script it out, but nothing i've learned or found on google, youtube, etc, has helped so far... Can somebody lend a hand? I need to know how to get Bash to execute a command with args:
execute like:
./nmap.sh -A -T4 -Pn x.x.x.x
#!/bin/bash
echo docker run --rm -it instrumentisto/nmap $1 $2 $3 $4 $5
but how to get bash to run this instead of just echo I dont know. Thanks ahead!
Two solutions: create an alias, create a script.
With an alias
The command you write is replaced with the value of the alias, so
alias nmap="docker run --rm -it instrumentisto/nmap"
nmap -A -T4 -Pn x.x.x.x
# executes docker run --rm -it instrumentisto/nmap -A -T4 -Pn x.x.x.x
Aliases are not persistent so you will have to store it in some bash config (generally ~/.bashrc).
With a script
#!/bin/bash
set -Eeuo pipefail
docker run --rm -it instrumentisto/nmap "$#"
"$#" will forward all the arguments provided to the script directly to the command. The quotes are important, if you call your script with quoted values like ./nmap "something with spaces", that's one argument, it needs to be kept as one argument.
Bonus: With a function
Just like the script, you need to forward arguments when writing functions, just like aliases, they are not persistent so you have to store them in bash config:
nmap() {
docker run --rm -it instrumentisto/nmap "$#"
}
I am on ubuntu 20.04 I installed docker using sudo snap install docker now when I run directly from the terminal (terminal installed with ubuntu) docker command it works fine but when I execute a .sh script from the terminal using either bash ./script.sh or ./script.sh I am getting an error docker: command not found.
This is the script:
#!/bin/bash
source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/env.sh
docker run -e "NODE_ENV=dev" -it --rm --name my-npm-2 -v $PROJECT_HOME/code:/var/www/html/code -w /var/www/html/code node:14 npm install
docker run -e "NODE_ENV=dev" -it --rm --name my-npm -v $PROJECT_HOME/code/web:/var/www/html/code/web -w /var/www/html/code/web node:14 npm install
$SCRIPT_HOME/buildjs_dev.sh
docker exec project_php sudo php -d memory_limit=-1 /usr/local/bin/composer install --working-dir=/var/www/html/code
docker exec project_php chown -R www-data:www-data /var/www/html/code/var/cache
docker exec project_php chown -R www-data:www-data /var/www/html/code/var/log
I am new to linux in general and I don't know if the problem is with the script itself or why isn't it recognizing docker?
You are defining a source file at the start of your script which might be changing the PATH variable. Try by either commenting the source line or calling the docker command with full path.
If I run the following command:
docker run -v "$PWD/aws":/root/.aws --rm -it amazon/aws-cli wafv2 list-ip-sets --profile dev --scope=CLOUDFRONT --region=us-east-1 --color off
I get the following output:
{
"IPSets": []
}
If I run the following command:
docker run -v "$PWD/aws":/root/.aws --rm -it amazon/aws-cli wafv2 list-ip-sets --profile dev --scope=CLOUDFRONT --region=us-east-1 --color off > test.txt
I get the following in test.txt:
[?1h=
{[m
"IPSets": [][m
}[m
[K[?1l>
I think these are xterm control codes or something - in any case, how do I get the contents of test.txt to match what is output to the terminal? I am on a Mac but my solution needs to work on Mac and Linux.
Apparently that -it parameter being passed to Docker was the problem. Passing just just -i made it work.
I wrote a bash file to automatically build a docker image and run the docker. The build goes fine however i get an invalid reference error for using $PWD. The command is as follows:
#!/bin/bash
app="docker.test2"
docker build -t ${app} .
docker run --rm -it -p 5000:5000 -v $PWD:/usr/src/Deployment -w /usr/src/Deployment/microblog2 ${app} flask run --host 0.0.0.0
When I replace the $PWD with the actual file path it works fine. I also tried replacing it with $pwd, $(pwd) and ${pwd} but to no avail. The error is as follows:
Docker/test:latest
should work fine
When I use docker run command, the variable "SPRING_PROFILES_ACTIVE" is right, but "SPRING_MAIN_WEB-APPLICATION-TYPE" does not work, how to pass "SPRING_MAIN_WEB-APPLICATION-TYPE" to dokcer image?
sudo docker run -d -e SPRING_PROFILES_ACTIVE=product -e SPRING_MAIN_WEB-APPLICATION-TYPE=SERVLET -e SERVER_PORT=6789 --network mongo_network
As described in the documentation, the expected format for that environment variable is SPRING_MAIN_WEBAPPLICATIONTYPE.
I use docker ENV to get it worked, here is the Dockerfile:
FROM openjdk:8-jre
ENV TYPE NONE
COPY data.jar data.jar
CMD ["java","-jar","data.jar", "--spring.main.web-application-type=${TYPE}"]
then run the docker image:
sudo docker run -d -e SPRING_PROFILES_ACTIVE=product -e TYPE=SERVLET -e SERVER_PORT=6789
hope this helps.