node.js - 我的 docker-compose 工作不正常?
问题描述
所以基本上我正在使用 docker-compose 一起运行 3 个服务。这些服务包括应用程序的 UI、PostgreSQL 数据库和应用程序的 API 服务器。
目前我已经尝试使用 docker-compose up 命令运行 docker-compose.yaml。目前我能够看到应用程序的 UI,但在 UI 页面本身有一个创建新文件夹的选项。但不幸的是,该选项在 UI 页面创建新文件夹不起作用。这显然意味着 api 服务器无法正常工作。
version: "3"
services:
pg_db:
image: postgres
networks:
- wootzinternal
ports:
- 5432
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=wootz
volumes:
- wootz-db:/var/lib/postgresql/data
apiserver:
image: wootz-backend
volumes:
- ./api:/usr/src/app
- /usr/src/app/node_modules
build:
context: ./api
dockerfile: Dockerfile
networks:
- wootzinternal
depends_on:
- pg_db
ports:
- '8000:8000'
ui:
image: wootz-frontend
volumes:
- ./client:/usr/src/app
- /usr/src/app/build
- /usr/src/app/node_modules
build:
context: ./client
dockerfile: Dockerfile
networks:
- wootzinternal
ports:
- '80:3000'
volumes:
wootz-db:
networks:
wootzinternal:
driver: bridge
用于 api 服务器的 Dockerfile
FROM node:12.4.0-alpine
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean --force
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
EXPOSE 8000
CMD [ "npm","start" ]
用于应用程序的 UI(客户端)的 Dockerfile
FROM node:12.4.0-alpine
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean --force
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
EXPOSE 3000
RUN npm run build
CMD [ "npm","start" ]
使用 dockerfile 创建 api 映像时使用的 config.json
{
"development": {
"username": "postgres",
"password": "password",
"database": "wootz",
"host": "pg_db",
"dialect": "postgres"
},
"test": {
"username": "postgres",
"password": "password",
"database": "wootz",
"host": "pg_db",
"dialect": "postgres"
},
"production": {
"username": "postgres",
"password": "password",
"database": "wootz",
"host": "pg_db",
"dialect": "postgres"
}
}
api server 容器中运行 npm run migrate 的日志
/usr/src/app # npm run migrate
> wootz-backend@1.0.0 migrate /usr/src/app
> sequelize db:migrate --config config/config.json
Sequelize CLI [Node: 12.4.0, CLI: 5.4.0, ORM: 5.8.7]
Loaded configuration file "config/config.json".
Using environment "development".
== 20190604071255-create-folders: migrating =======
== 20190604071255-create-folders: migrated (0.027s)
== 20190604072132-create-views: migrating =======
== 20190604072132-create-views: migrated (0.018s)
docker-compose 的日志
vignesh@master-node:~/cors new files$ sudo docker-compose logs
sudo: unable to resolve host master-node
Attaching to corsnewfiles_apiserver_1, corsnewfiles_ui_1, corsnewfiles_pg_db_1
apiserver_1 |
apiserver_1 | > wootz-backend@1.0.0 start /usr/src/app
apiserver_1 | > nodemon index.js
apiserver_1 |
apiserver_1 | [nodemon] 1.19.1
apiserver_1 | [nodemon] to restart at any time, enter `rs`
apiserver_1 | [nodemon] watching: *.*
apiserver_1 | [nodemon] starting `node index.js`
apiserver_1 | {
apiserver_1 | username: 'postgres',
apiserver_1 | password: 'password',
apiserver_1 | database: 'wootz',
apiserver_1 | host: 'pg_db',
apiserver_1 | dialect: 'postgres'
apiserver_1 | }
apiserver_1 | folders
apiserver_1 | views
apiserver_1 | Listening on port 8000
pg_db_1 | The files belonging to this database system will be owned by user "postgres".
pg_db_1 | This user must also own the server process.
pg_db_1 |
pg_db_1 | The database cluster will be initialized with locale "en_US.utf8" .
pg_db_1 | The default database encoding has accordingly been set to "UTF8".
pg_db_1 | The default text search configuration will be set to "english".
pg_db_1 |
pg_db_1 | Data page checksums are disabled.
pg_db_1 |
pg_db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
pg_db_1 | creating subdirectories ... ok
pg_db_1 | selecting default max_connections ... 100
pg_db_1 | selecting default shared_buffers ... 128MB
pg_db_1 | selecting default timezone ... Etc/UTC
ui_1 |
pg_db_1 | selecting dynamic shared memory implementation ... posix
ui_1 | > wootz@0.1.0 start /usr/src/app
pg_db_1 | creating configuration files ... ok
ui_1 | > node scripts/start.js
pg_db_1 | running bootstrap script ... ok
ui_1 |
pg_db_1 | performing post-bootstrap initialization ... ok
ui_1 | Starting the development server...
pg_db_1 |
ui_1 |
pg_db_1 | WARNING: enabling "trust" authentication for local connections
ui_1 | Compiled with warnings.
pg_db_1 | You can change this by editing pg_hba.conf or using the option -A , or
ui_1 |
pg_db_1 | --auth-local and --auth-host, the next time you run initdb.
ui_1 | ./src/registeredComponent/temporary/temporary.js
pg_db_1 | syncing data to disk ... ok
ui_1 | Line 1: 'Component' is defined but never used no-unused-vars
pg_db_1 |
ui_1 |
pg_db_1 | Success. You can now start the database server using:
ui_1 | ./src/registeredComponent/textFiled/textFiled.js
pg_db_1 |
ui_1 | Line 1: 'Component' is defined but never used no-unused-vars
ui_1 |
ui_1 | ./src/components/Data/dragAndDrop/master.js
pg_db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
pg_db_1 |
pg_db_1 | waiting for server to start....2019-07-03 05:49:53.111 UTC [43] L OG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
pg_db_1 | 2019-07-03 05:49:53.128 UTC [44] LOG: database system was shut d own at 2019-07-03 05:49:52 UTC
pg_db_1 | 2019-07-03 05:49:53.133 UTC [43] LOG: database system is ready t o accept connections
pg_db_1 | done
ui_1 | Line 22: 'Link' is defined but never used no-unused-vars
pg_db_1 | server started
pg_db_1 | CREATE DATABASE
ui_1 |
pg_db_1 |
ui_1 | ./src/components/Data/formListing/Formlisting.js
pg_db_1 |
ui_1 | Line 49: 'mapStateToProps' is assigned a value but never used no-unused-vars
ui_1 |
pg_db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint- initdb.d/*
ui_1 | ./src/common/getFieldList.js
pg_db_1 |
ui_1 | Line 54: Expected to return a value at the end of arrow funct ion array-callback-return
ui_1 | Line 158: Expected to return a value at the end of arrow funct ion array-callback-return
pg_db_1 | waiting for server to shut down...2019-07-03 05:49:53.497 UTC [43 ] LOG: received fast shutdown request
pg_db_1 | .2019-07-03 05:49:53.499 UTC [43] LOG: aborting any active trans actions
ui_1 |
pg_db_1 | 2019-07-03 05:49:53.501 UTC [43] LOG: background worker "logical replication launcher" (PID 50) exited with exit code 1
ui_1 | ./src/common/common.js
pg_db_1 | 2019-07-03 05:49:53.508 UTC [45] LOG: shutting down
pg_db_1 | 2019-07-03 05:49:53.519 UTC [43] LOG: database system is shut do wn
ui_1 | Line 551: Expected to return a value at the end of arrow funct ion array-callback-return
pg_db_1 | done
ui_1 |
pg_db_1 | server stopped
ui_1 | ./src/components/Data/formListing/FolderList.js
pg_db_1 |
ui_1 | Line 5: Useless constructor no-useless-constructor
pg_db_1 | PostgreSQL init process complete; ready for start up.
ui_1 |
pg_db_1 |
ui_1 | ./src/components/Data/launchScreen/launchScreen.js
pg_db_1 | 2019-07-03 05:49:53.611 UTC [1] LOG: listening on IPv4 address " 0.0.0.0", port 5432
ui_1 | Line 75: 'newfolder' is assigned a value but never used no-unused-vars
pg_db_1 | 2019-07-03 05:49:53.611 UTC [1] LOG: listening on IPv6 address " ::", port 5432
ui_1 | Line 75: 'alert' is assigned a value but never used no-unused-vars
pg_db_1 | 2019-07-03 05:49:53.613 UTC [1] LOG: listening on Unix socket "/ var/run/postgresql/.s.PGSQL.5432"
ui_1 | Line 75: 'alertMessage' is assigned a value but never used no-unused-vars
pg_db_1 | 2019-07-03 05:49:53.629 UTC [61] LOG: database system was shut d own at 2019-07-03 05:49:53 UTC
ui_1 | Line 161: No duplicate props allowed react/jsx-no-duplicate-pr ops
pg_db_1 | 2019-07-03 05:49:53.635 UTC [1] LOG: database system is ready to accept connections
ui_1 | Line 167: img elements must have an alt prop, either with mean ingful text, or an empty string for decorative images jsx-a11y/alt-text
ui_1 | Line 182: img elements must have an alt prop, either with mean ingful text, or an empty string for decorative images jsx-a11y/alt-text
ui_1 | Line 191: img elements must have an alt prop, either with mean ingful text, or an empty string for decorative images jsx-a11y/alt-text
ui_1 | Line 202: img elements must have an alt prop, either with mean ingful text, or an empty string for decorative images jsx-a11y/alt-text
ui_1 |
ui_1 | Search for the keywords to learn more about each warning.
ui_1 | To ignore, add // eslint-disable-next-line to the line before.
ui_1 |
我希望能够在 UI 页面中创建一个新文件夹,这将表明 api 服务器工作正常。但不幸的是,目前我只能在浏览器中看到 UI 页面而无法创建新文件夹。
解决方案
推荐阅读
- mongodb - MongoDB:使用来自另一个字段的值更新字段
- javascript - 使用 angularjs 使用属性检查取消选中复选框
- elasticsearch - 如何更改 Elastic Search 上搜索结果的顺序?
- php - 如何在 Laravel 中使用多对多关系检索嵌套类别的产品并对结果进行排序?
- python - 得到一个错误“预期的二维数组,得到一维数组”,拆分数据集(csv)以使线性
- java - 使用具有多种功能的扫描仪的正确方法?
- android - Gradle Build 上的 Axion 发布插件错误
- android - 创建从 Fire Base 加载的可搜索微调器
- python - selenium python中的send_keys使用chrome web驱动程序很慢
- python-3.x - 为 Gensim 模型绘制 3D 图