Docker, MySQL - command not found in .sh file
up vote
0
down vote
favorite
I'm relatively new to Docker. I just set up a Dockerfile and a docker-compose.yml. And for some reason, docker cannot run this script. Whenever this script is run, it goes through all SQL files and migrates that file
#!/bin/bash
DB_NAME="database_name"
DB_USER="username"
DB_PASS="password"
DB_HOST="localhost"
#get current version
GET_DATABASE_VERSION="SELECT name FROM version TOP 1"
#
echo "Getting data version"
version=$(mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT name FROM version")
#trim string to get current version name
version=${version:5}
x="./config/scripts/migration/$version"
echo $version
MIGRATION_PATH="./config/scripts/migration/*"
#get migration file for newer version
for filename in $MIGRATION_PATH -maxdepth 2
do
if [[ -f $filename ]]; then
if [[ "$filename" > "$x" ]] || [ "$filename" == "$x" ]; then
echo "Running migration file: $filename"
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename
fi
fi
done
I keep getting error messages ./config/scripts/migrate_local.sh: line 25: mysql: command not found which is this line mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename.
Does anyone know how to fix this? Here are the Dockerfile and docker-compose.yml, I'm using sudo docker-compose up --build to run.
Dockerfile
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
docker-compose.yml
version: "2"
services:
universe:
build: .
working_dir: /usr/src
environment:
- NODE_ENV=default
- PORT=3000
volumes:
- /usr/src
ports:
- "3000:3000"
- "8000:8000"
links:
- redis
- mysql
redis:
image: redis
volumes:
- /data/redis:/data
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "database_name"
MYSQL_USER: "username"
MYSQL_PASSWORD: "password"
volumes:
- /data/mysql:/var/lib/mysql
UPDATE
I use winston as my logger, however, it doesn't work whatsoever, console.log works fine. This might be the error:
universe_1 | errno: 'ECONNREFUSED',
universe_1 | code: 'ECONNREFUSED',
universe_1 | syscall: 'connect',
universe_1 | address: '127.0.0.1',
universe_1 | port: 3307,
universe_1 | fatal: true
mysql node.js docker docker-compose
add a comment |
up vote
0
down vote
favorite
I'm relatively new to Docker. I just set up a Dockerfile and a docker-compose.yml. And for some reason, docker cannot run this script. Whenever this script is run, it goes through all SQL files and migrates that file
#!/bin/bash
DB_NAME="database_name"
DB_USER="username"
DB_PASS="password"
DB_HOST="localhost"
#get current version
GET_DATABASE_VERSION="SELECT name FROM version TOP 1"
#
echo "Getting data version"
version=$(mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT name FROM version")
#trim string to get current version name
version=${version:5}
x="./config/scripts/migration/$version"
echo $version
MIGRATION_PATH="./config/scripts/migration/*"
#get migration file for newer version
for filename in $MIGRATION_PATH -maxdepth 2
do
if [[ -f $filename ]]; then
if [[ "$filename" > "$x" ]] || [ "$filename" == "$x" ]; then
echo "Running migration file: $filename"
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename
fi
fi
done
I keep getting error messages ./config/scripts/migrate_local.sh: line 25: mysql: command not found which is this line mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename.
Does anyone know how to fix this? Here are the Dockerfile and docker-compose.yml, I'm using sudo docker-compose up --build to run.
Dockerfile
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
docker-compose.yml
version: "2"
services:
universe:
build: .
working_dir: /usr/src
environment:
- NODE_ENV=default
- PORT=3000
volumes:
- /usr/src
ports:
- "3000:3000"
- "8000:8000"
links:
- redis
- mysql
redis:
image: redis
volumes:
- /data/redis:/data
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "database_name"
MYSQL_USER: "username"
MYSQL_PASSWORD: "password"
volumes:
- /data/mysql:/var/lib/mysql
UPDATE
I use winston as my logger, however, it doesn't work whatsoever, console.log works fine. This might be the error:
universe_1 | errno: 'ECONNREFUSED',
universe_1 | code: 'ECONNREFUSED',
universe_1 | syscall: 'connect',
universe_1 | address: '127.0.0.1',
universe_1 | port: 3307,
universe_1 | fatal: true
mysql node.js docker docker-compose
where this script is running? on youruniverseimage?
– Emruz Hossain
Nov 9 at 5:39
@EmruzHossain yeah exactly, here is the scriptchmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.shrunning inside theuniverseimage. I updated what I found, that's might be the error
– Tri Nguyen
Nov 9 at 6:35
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm relatively new to Docker. I just set up a Dockerfile and a docker-compose.yml. And for some reason, docker cannot run this script. Whenever this script is run, it goes through all SQL files and migrates that file
#!/bin/bash
DB_NAME="database_name"
DB_USER="username"
DB_PASS="password"
DB_HOST="localhost"
#get current version
GET_DATABASE_VERSION="SELECT name FROM version TOP 1"
#
echo "Getting data version"
version=$(mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT name FROM version")
#trim string to get current version name
version=${version:5}
x="./config/scripts/migration/$version"
echo $version
MIGRATION_PATH="./config/scripts/migration/*"
#get migration file for newer version
for filename in $MIGRATION_PATH -maxdepth 2
do
if [[ -f $filename ]]; then
if [[ "$filename" > "$x" ]] || [ "$filename" == "$x" ]; then
echo "Running migration file: $filename"
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename
fi
fi
done
I keep getting error messages ./config/scripts/migrate_local.sh: line 25: mysql: command not found which is this line mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename.
Does anyone know how to fix this? Here are the Dockerfile and docker-compose.yml, I'm using sudo docker-compose up --build to run.
Dockerfile
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
docker-compose.yml
version: "2"
services:
universe:
build: .
working_dir: /usr/src
environment:
- NODE_ENV=default
- PORT=3000
volumes:
- /usr/src
ports:
- "3000:3000"
- "8000:8000"
links:
- redis
- mysql
redis:
image: redis
volumes:
- /data/redis:/data
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "database_name"
MYSQL_USER: "username"
MYSQL_PASSWORD: "password"
volumes:
- /data/mysql:/var/lib/mysql
UPDATE
I use winston as my logger, however, it doesn't work whatsoever, console.log works fine. This might be the error:
universe_1 | errno: 'ECONNREFUSED',
universe_1 | code: 'ECONNREFUSED',
universe_1 | syscall: 'connect',
universe_1 | address: '127.0.0.1',
universe_1 | port: 3307,
universe_1 | fatal: true
mysql node.js docker docker-compose
I'm relatively new to Docker. I just set up a Dockerfile and a docker-compose.yml. And for some reason, docker cannot run this script. Whenever this script is run, it goes through all SQL files and migrates that file
#!/bin/bash
DB_NAME="database_name"
DB_USER="username"
DB_PASS="password"
DB_HOST="localhost"
#get current version
GET_DATABASE_VERSION="SELECT name FROM version TOP 1"
#
echo "Getting data version"
version=$(mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME -e "SELECT name FROM version")
#trim string to get current version name
version=${version:5}
x="./config/scripts/migration/$version"
echo $version
MIGRATION_PATH="./config/scripts/migration/*"
#get migration file for newer version
for filename in $MIGRATION_PATH -maxdepth 2
do
if [[ -f $filename ]]; then
if [[ "$filename" > "$x" ]] || [ "$filename" == "$x" ]; then
echo "Running migration file: $filename"
mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename
fi
fi
done
I keep getting error messages ./config/scripts/migrate_local.sh: line 25: mysql: command not found which is this line mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename.
Does anyone know how to fix this? Here are the Dockerfile and docker-compose.yml, I'm using sudo docker-compose up --build to run.
Dockerfile
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
docker-compose.yml
version: "2"
services:
universe:
build: .
working_dir: /usr/src
environment:
- NODE_ENV=default
- PORT=3000
volumes:
- /usr/src
ports:
- "3000:3000"
- "8000:8000"
links:
- redis
- mysql
redis:
image: redis
volumes:
- /data/redis:/data
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "database_name"
MYSQL_USER: "username"
MYSQL_PASSWORD: "password"
volumes:
- /data/mysql:/var/lib/mysql
UPDATE
I use winston as my logger, however, it doesn't work whatsoever, console.log works fine. This might be the error:
universe_1 | errno: 'ECONNREFUSED',
universe_1 | code: 'ECONNREFUSED',
universe_1 | syscall: 'connect',
universe_1 | address: '127.0.0.1',
universe_1 | port: 3307,
universe_1 | fatal: true
mysql node.js docker docker-compose
mysql node.js docker docker-compose
edited Nov 9 at 6:42
asked Nov 9 at 4:03
Tri Nguyen
316419
316419
where this script is running? on youruniverseimage?
– Emruz Hossain
Nov 9 at 5:39
@EmruzHossain yeah exactly, here is the scriptchmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.shrunning inside theuniverseimage. I updated what I found, that's might be the error
– Tri Nguyen
Nov 9 at 6:35
add a comment |
where this script is running? on youruniverseimage?
– Emruz Hossain
Nov 9 at 5:39
@EmruzHossain yeah exactly, here is the scriptchmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.shrunning inside theuniverseimage. I updated what I found, that's might be the error
– Tri Nguyen
Nov 9 at 6:35
where this script is running? on your
universe image?– Emruz Hossain
Nov 9 at 5:39
where this script is running? on your
universe image?– Emruz Hossain
Nov 9 at 5:39
@EmruzHossain yeah exactly, here is the script
chmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.sh running inside the universe image. I updated what I found, that's might be the error– Tri Nguyen
Nov 9 at 6:35
@EmruzHossain yeah exactly, here is the script
chmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.sh running inside the universe image. I updated what I found, that's might be the error– Tri Nguyen
Nov 9 at 6:35
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
your universe image does not have mysql command line tools installed. you have to install it while building docker image.
Try following Dockerfile:
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
RUN set -ex;
apt-get update;
apt-get install -y --no-install-recommends
mysql-client
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
Thanks. It's solved the above problem but this problem came upERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
– Tri Nguyen
Nov 9 at 7:34
try usingDB_HOST="127.0.0.1"instead ofDB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…
– Emruz Hossain
Nov 9 at 8:23
I gotERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I thinklocalhostwas correct, it's something with permission of/var/run/mysqld/mysqld.sock
– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
|
show 4 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
your universe image does not have mysql command line tools installed. you have to install it while building docker image.
Try following Dockerfile:
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
RUN set -ex;
apt-get update;
apt-get install -y --no-install-recommends
mysql-client
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
Thanks. It's solved the above problem but this problem came upERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
– Tri Nguyen
Nov 9 at 7:34
try usingDB_HOST="127.0.0.1"instead ofDB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…
– Emruz Hossain
Nov 9 at 8:23
I gotERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I thinklocalhostwas correct, it's something with permission of/var/run/mysqld/mysqld.sock
– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
|
show 4 more comments
up vote
1
down vote
your universe image does not have mysql command line tools installed. you have to install it while building docker image.
Try following Dockerfile:
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
RUN set -ex;
apt-get update;
apt-get install -y --no-install-recommends
mysql-client
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
Thanks. It's solved the above problem but this problem came upERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
– Tri Nguyen
Nov 9 at 7:34
try usingDB_HOST="127.0.0.1"instead ofDB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…
– Emruz Hossain
Nov 9 at 8:23
I gotERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I thinklocalhostwas correct, it's something with permission of/var/run/mysqld/mysqld.sock
– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
|
show 4 more comments
up vote
1
down vote
up vote
1
down vote
your universe image does not have mysql command line tools installed. you have to install it while building docker image.
Try following Dockerfile:
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
RUN set -ex;
apt-get update;
apt-get install -y --no-install-recommends
mysql-client
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
your universe image does not have mysql command line tools installed. you have to install it while building docker image.
Try following Dockerfile:
FROM node:8
MAINTAINER Tri Nguyen "me@mydomain.com"
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY package.json /usr/src
RUN npm install
RUN npm rebuild node-sass --force
RUN set -ex;
apt-get update;
apt-get install -y --no-install-recommends
mysql-client
COPY . /usr/src
EXPOSE 3000 8000
CMD [ "npm", "start" ]
answered Nov 9 at 7:13
Emruz Hossain
1,021210
1,021210
Thanks. It's solved the above problem but this problem came upERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
– Tri Nguyen
Nov 9 at 7:34
try usingDB_HOST="127.0.0.1"instead ofDB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…
– Emruz Hossain
Nov 9 at 8:23
I gotERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I thinklocalhostwas correct, it's something with permission of/var/run/mysqld/mysqld.sock
– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
|
show 4 more comments
Thanks. It's solved the above problem but this problem came upERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
– Tri Nguyen
Nov 9 at 7:34
try usingDB_HOST="127.0.0.1"instead ofDB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…
– Emruz Hossain
Nov 9 at 8:23
I gotERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I thinklocalhostwas correct, it's something with permission of/var/run/mysqld/mysqld.sock
– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
Thanks. It's solved the above problem but this problem came up
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)– Tri Nguyen
Nov 9 at 7:34
Thanks. It's solved the above problem but this problem came up
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)– Tri Nguyen
Nov 9 at 7:34
try using
DB_HOST="127.0.0.1" instead of DB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…– Emruz Hossain
Nov 9 at 8:23
try using
DB_HOST="127.0.0.1" instead of DB_HOST="localhost". Ref: help.memsql.com/hc/en-us/articles/…– Emruz Hossain
Nov 9 at 8:23
I got
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I think localhost was correct, it's something with permission of /var/run/mysqld/mysqld.sock– Tri Nguyen
Nov 9 at 8:47
I got
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111). I think localhost was correct, it's something with permission of /var/run/mysqld/mysqld.sock– Tri Nguyen
Nov 9 at 8:47
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
are you able to access mysql database from local machine?
– Emruz Hossain
Nov 9 at 8:59
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
Yes it runs perfectly fine
– Tri Nguyen
Nov 9 at 9:02
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219709%2fdocker-mysql-command-not-found-in-sh-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
where this script is running? on your
universeimage?– Emruz Hossain
Nov 9 at 5:39
@EmruzHossain yeah exactly, here is the script
chmod +x ./config/scripts/dbsetup_local.sh && ./config/scripts/dbsetup_local.shrunning inside theuniverseimage. I updated what I found, that's might be the error– Tri Nguyen
Nov 9 at 6:35