This is working.
oc new-app --docker-image=docker.mycompany.com/myusername/my-imagestuff:latest -e SPRING_DATASOURCE_URL="jdbc:sqlserver://blahblahblah;” -e SPRING_DATASOURCE_USERNAME=“myUserName1” -e SPRING_DATASOURCE_PASSWORD=“MyP#ssword” -e
so I went back and added the datasource-classname
oc new-app --docker-image=docker.mycompany.com/myusername/my-imagestuff:latest -e SPRING_DATASOURCE_URL="jdbc:sqlserver://blahblahblah;” -e SPRING_DATASOURCE_USERNAME=“myUserName1” -e SPRING_DATASOURCE_PASSWORD=“MyP#ssword” -e SPRING_DATASOURCE_DRIVER-CLASS-NAME="com.microsoft.sqlserver.jdbc.SQLServerDriver"
and now my deployments are failing with this error:
error: invalid parameter assignment in
"SPRING_DATASOURCE_DRIVER-CLASS-NAME=com.microsoft.sqlserver.jdbc.SQLServerDriver"
What is the magic sauce of hyphen / hyphens and/or periods / dots in the environment variable and value
?
Thanks!
You're unable to use environment variables that contain hyphens or periods because those characters are not valid in shell variable names:
➜ tmp.0ngsgXro foo.bar=1
zsh: command not found: foo.bar=1
➜ tmp.0ngsgXro foo-bar=1
zsh: command not found: foo-bar=1
➜ tmp.0ngsgXro foo_bar=1
➜ tmp.0ngsgXro echo $foo_bar
1
You're trying to create an environment variable in your container that violates the rules of the underlying shell.
So out of desperation, I changed the hyphens to underscores.
Note the last argument of SPRING_DATASOURCE_DRIVER_CLASS_NAME
oc new-app --docker-image=docker.mycompany.com/myusername/my-imagestuff:latest -e SPRING_DATASOURCE_URL="jdbc:sqlserver://blahblahblah;” -e SPRING_DATASOURCE_USERNAME=“myUserName1” -e SPRING_DATASOURCE_PASSWORD=“MyP#ssword” -e SPRING_DATASOURCE_DRIVER_CLASS_NAME="com.microsoft.sqlserver.jdbc.SQLServerDriver"
And my app is working. So I am writing this answer.
I do not understand this voodoo.
If someone can explain it, I'd be grateful.
Related
Hello currently I get in touch with Docker. I am doing their getting started and I ran into a problem which I cant solve and I dont understand why it dont work. First of all I create a network using.
$ docker network create todo-app
After that, I set up a Container mysql database and connect it with the network with following code.
$ docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
I check for the Container id with
$ docker ps
After that I use the command to get into the mysql CLI ? (not sure on that yet)
$ docker exec -it mysql -u root -p
After getting there I use
mysql> SHOW DATABASES;
to show all DB on my PC? But there is non listed named todos and i dont know why it dont appear.
I would like to hear what you are thinking im struggeling a little there. Thanks for the replies. Sorry for my english skills.
Run container in the foreground and check the logs.
Following Part 7: Multi-container apps, I ran into this exact issue just now.
Chances are, you have run that same command at least once.
# command to run as per the docs
docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
And the first time you ran the command you unknowingly made a mistake. For me, I mistyped MYSQL_DATABASE FOR MYSQL_ROOT_PASSWORD. Yours might be different. In any case, it seems making small mistakes like this might have caused the mysql:5.7 image to not be set up correctly with the todos database. (Not entirely sure.)
Adding to that, the first time you run that command, Docker creates a todo-mysql-data volume, which does not get overwritten when you run that same command again.
So as a "fix", you might have to delete the todo-mysql-data volume first.
docker volume rm todo-mysql-data
And then re-create the todo-mysql-data volume implicitly by re-running the image with the above command; this time without mistakes.
Sorry for the trouble it was my fault I guess cause I used the Command I pointed out above but I definetly had to use this command :
docker run -d \
--network todo-app --network-alias mysql \
--platform "linux/amd64" \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
Because im using Linux... Such a dumb mistake but i swear this wasnt there two months ago when I asked this Qeustion.
I'm following this guide to use MySQL 8.0 in Docker (on macOS host), but I'm having some issues. I have no Docker experience other than this, so please be easy on me. I tried to debug as best I could. It seems the author of the guide has some outdated commands/syntax errors (not sure which), which I think I've fixed. However, when I try to run the following command, I keep getting the error below:
Command:
docker run --restart always --name mysql8.0 --network dev-network -v /Users/[my-name]/mysql/data/8.0:/var/lib/mysql -p 3306:3308 -d -e MYSQL_ROOT_PASSWORD=[my-password] mysql:8.0
( [my-name] and [my-password] are subbed out).
Error:
"docker run" requires at least 1 argument.
I've checked docker run --help but can't get any further.
I've also found this question and this question, but those cases seem highly specific to the OPs' situation, so the answers didn't yield any successful results for me.
Any help or suggestions are appreciated.
The command you've pasted works fine. There is a possibility that the password you're entering has some special characters making the shell think of it as something else. (Or your volume next to -v flag has some special characters).
Just to test, try with a simple password like this:
docker run --restart always --name mysql8.0 --network dev-network -v /Users/[yourusername]/mysql/data/8.0:/var/lib/mysql -p 3306:3308 -d -e MYSQL_ROOT_PASSWORD=testpass
mysql:8.0
I have a bash script that is executed via a cron job
#!/bin/bash
# abort on errors
set -e
ABS_DIR=/path/
# extract the creds for the mysql db
DB_USER="USERNAME"
DB_PASS="PASSWORD"
function extract_data() {
file=$2
sql_query=`cat $ABS_DIR/$1`
data=`mysql -u $DB_USER --password="$DB_PASS" -D "database" -e "$sql_query" | tail -n +2`
echo -e "Data:"
echo -e "$data"
}
extract_data "sql_query.sql" "log.csv"
When running it manually with bash extract.sh the mysql cmd fetches the data correctly and I see the echo -e "$data" on the console.
When running the script via a cron job
* 12 * * * /.../extract.sh > /.../cron_log.txt
then I get an empty line saved to the cron_log.txt file!?
This is a common problem; a script behaves differently when run from user shell and when run from crontab. The cause is typically due to differences in the environment variables in the user shell, and in the crontab shell; by default, they are not the same.
To begin debugging this issue, you could direct stderr as well as stdout from crontab, hopefully to capture an error message:
extract.sh &> /.../cron_log.txt
(notice the &)
Also: you have three dots (/.../) -- that is likely a typo, could also be the cause.
I pass the following as my GCE startup script but it always logs in as the root user and never as the demo-user. How do I fix it?
let startupScript = `#!/bin/bash
su demo-user
WHO_AM_I=$(whoami)
echo WHO_AM_I: $WHO_AM_I &>> debug.txt
cd..`
I think it should work like that:
#! /bin/bash
sudo -u demo-user bash -c 'WHO_AM_I=$(whoami);
echo WHO_AM_I; $WHO_AM_I &>> debug.txt;'
use "sudo-u" to specify the user, then bash -c 'with all the commands between these particular quotes '' and separated by ;
For example: bash -c 'command1; command2;'
You can try an easier test (it worked for me), for example:
#! /bin/bash
sudo -u demo-user bash -c 'touch test.txt'
And then check with ls -l /home/demo-test/text.txt that demo-test is the owner of the new file.
I'm new to tcl. I'm trying to run some commands with tcl script.
I searched online and came to know that we can run unix commands with tcl using exec
I executed the following;
perl -i -p -e 's/hello linux./hello fedora. /g;' sample1.txt
from the commandline and it worked. it replaced all the occurences of hello linux with hello fedora.
I tried executing the same command in my tcl script.
set result [exec perl -i -p -e 's/hello linux./hello fedora. /g;' sample.txt]
I got the below error :
child process exited abnormally
I also tried using sed command. I got the same error. I guess there is something wrong with the syntax. I searched online but i couldn't figure it out on my own.
' is not a grouping character in tcl. The equivalent grouping in tcl is {}. Therefore the correct statement is:
exec perl -i -p -e {s/hello linux./hello fedora. /g;} sample.txt
Or even:
exec perl -i -p -e "s/hello linux./hello fedora. /g;" sample.txt