我对 Docker 还比较陌生。我刚建立了一个 Dockerfile
和一个 docker-compose.yml
. 由于某些原因,docker无法运行此脚本。每当运行此脚本时,它都会遍历所有sql文件并迁移该文件
# !/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
我不断收到错误信息 ./config/scripts/migrate_local.sh: line 25: mysql: command not found
这是哪条线 mysql -h$DB_HOST -u$DB_USER -p$DB_PASS $DB_NAME < $filename
.
有人知道怎么解决这个问题吗?这是你的名字 Dockerfile
以及 docker-compose.yml
,我正在使用 sudo docker-compose up --build
跑。
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
我使用的更新 winston
不过,作为我的记录者,它根本不起作用, console.log
很好用。这可能是错误:
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
1条答案
按热度按时间j7dteeu81#
你的
universe
图像没有mysql
已安装命令行工具。您必须在构建docker映像时安装它。尝试以下dockerfile: