我一直在尝试运行我的docker compose文件,我不断得到相同的错误,端口已经在使用中。当我在端口3003中运行服务时,我让它工作,但是每次我尝试编写docker时,我都会得到一个错误,即该端口已经在使用中。是的,在运行docker文件之前,我关闭了在端口3003上运行的服务。
下面是我的docker-compose.yaml:
version: "3"
services:
redis:
container_name: redis
image: redis
restart: always
command: ["redis-server", "--bind", "0.0.0.0", "--port", "6379"]
ports:
- "6379:6379"
environment:
- ALLOW_EMPTY_PASSWORD=yes
app:
container_name: photo-gallery
restart: always
build: .
ports:
- "80:3003"
links:
- redis
- mongo
# environment:
# MONGO_USERNAME: root
# MONGO_PASSWORD:
mongo:
container_name: mongo
image: mongo
restart: always
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
# MONGO_INITDB_ROOT_PASSWORD:
ports:
- "27017:27017"
下面是我的server/index.js文件:
require('newrelic');
const express = require('express');
const bodyParser = require('body-parser');
const db = require('../database-mongo/index.js');
const cors = require('cors');
const redis = require('redis');
const client = redis.createClient();
// const RedisServer = require('redis-server');
// const server = new RedisServer(6379);
const PORT = 3003;
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + '/../react-client/dist'));
// server.open((err) => {
// if (err === null) {
// console.log('redis server working')
// }
// })
let redisMiddleware = (req, res, next) => {
let key = "__expIress__" + req.originalUrl || req.url;
client.get(key, function (err, reply) {
if (reply) {
// Needs to be parsed first because its getting a stringified object out of its own database so it can be returned in the proper shape
res.send(JSON.parse(reply));
} else {
res.sendResponse = res.send;
res.send = (body) => {
client.set(key, JSON.stringify(body));
res.sendResponse(body);
}
next();
}
});
};
app.get('/images/urls/:itemId', redisMiddleware, (req, res) => {
db.fetchItemImages(req.params.itemId)
.then((data) => {
if (data) {
client.set(req.params.itemId, JSON.stringify({ data }))
res.status(200).send({ data });
} else {
res.sendStatus(404);
}
})
.catch((err) => {
console.log('error with app.get: ', err);
res.status(500).send(err);
})
})
app.post('/images/urls/:itemId', (req, res) => {
// console.log('this is the req.body: ', req.body)
db.insertRecords(req.body)
.then((data) => {
if (data) {
// console.log('this is the data from post: ', data)
res.sendStatus(200)
} else {
res.sendStatus(404)
}
})
})
app.put('/images/urls/:itemId', (req, res) => {
console.log('req.params.itemId: ', req.params.itemId)
db.updateOne({ itemId: req.params.itemId }, req.body)
.then((data) => {
console.log('this is the data: ', data)
if (data) {
// console.log('data from updateOne: ', data)
res.sendStatus(200);
} else {
res.sendStatus(404);
}
})
.catch((err) => {
res.status(500).send(err);
console.log('error with put request: ', err);
})
})
app.delete('/itemImages/:itemId', (req, res) => {
db.deleteOne(req.params.itemId)
.then((data) => {
if (data) {
res.sendStatus(200);
} else {
res.sendStatus(404);
}
})
.catch((err) => {
res.status(500).send(err);
console.log('error with patch request: ', err);
})
})
app.listen(PORT, () => {
console.log(`listening on port ${PORT}`);
});
module.exports = app
下面是我的dockerfile:
# Usually to select particular version instead of latest
FROM node:10.15.3 as base
RUN mkdir -p /srv/app
COPY . /srv/app
WORKDIR /srv/app
# Install production dependencies
RUN npm install
RUN npm run build_client
# Expose port for access outside of container
ENV PORT 3003
EXPOSE $PORT
CMD ["node", "server/index.js"]
运行docker compose up时,出现以下错误:
Creating redis ... done
Creating mongo ... done
Creating photo-gallery ... done
Attaching to mongo, redis, photo-gallery
mongo | {"t":{"$date":"2020-10-02T03:49:26.468+00:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
mongo | {"t":{"$date":"2020-10-02T03:49:26.492+00:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
mongo | {"t":{"$date":"2020-10-02T03:49:26.492+00:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
mongo | {"t":{"$date":"2020-10-02T03:49:26.495+00:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"40995b77e382"}}
mongo | {"t":{"$date":"2020-10-02T03:49:26.495+00:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:26.495+00:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"18.04"}}}
mongo | {"t":{"$date":"2020-10-02T03:49:26.495+00:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:26.509+00:00"},"s":"I", "c":"STORAGE", "id":22297, "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}
mongo | {"t":{"$date":"2020-10-02T03:49:26.509+00:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=483M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
redis | 1:C 02 Oct 2020 03:49:25.870 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis | 1:C 02 Oct 2020 03:49:25.870 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis | 1:C 02 Oct 2020 03:49:25.870 # Configuration loaded
redis | 1:M 02 Oct 2020 03:49:25.888 * Running mode=standalone, port=6379.
redis | 1:M 02 Oct 2020 03:49:25.889 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis | 1:M 02 Oct 2020 03:49:25.889 # Server initialized
redis | 1:M 02 Oct 2020 03:49:25.890 * Ready to accept connections
photo-gallery | Unable to find New Relic module configuration. A base configuration file
photo-gallery | can be copied from /srv/app/node_modules/newrelic/newrelic.js
photo-gallery | and put at /srv/app/newrelic.js or
photo-gallery | /srv/app/server/newrelic.js.
photo-gallery | If you are not using file-based configuration, please set the environment
photo-gallery | variable `NEW_RELIC_NO_CONFIG_FILE=true`.
photo-gallery | Unable to find New Relic module configuration. A base configuration file
photo-gallery | can be copied from /srv/app/node_modules/newrelic/newrelic.js
photo-gallery | and put at /srv/app/newrelic.js or
photo-gallery | /srv/app/server/newrelic.js.
photo-gallery | If you are not using file-based configuration, please set the environment
photo-gallery | variable `NEW_RELIC_NO_CONFIG_FILE=true`.
mongo | {"t":{"$date":"2020-10-02T03:49:30.249+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1601610570:243209][1:0x7f40082c7a80], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.250+00:00"},"s":"I", "c":"STORAGE", "id":22430, "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1601610570:250216][1:0x7f40082c7a80], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.345+00:00"},"s":"I", "c":"STORAGE", "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":3836}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.345+00:00"},"s":"I", "c":"RECOVERY", "id":23987, "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.426+00:00"},"s":"I", "c":"STORAGE", "id":22262, "ctx":"initandlisten","msg":"Timestamp monitor starting"}
mongo | {"t":{"$date":"2020-10-02T03:49:30.483+00:00"},"s":"W", "c":"CONTROL", "id":22120, "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
mongo | {"t":{"$date":"2020-10-02T03:49:30.535+00:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"f53f1b4a-9798-4b38-a8bd-f499bdc45f6b"}},"options":{"uuid":{"$uuid":"f53f1b4a-9798-4b38-a8bd-f499bdc45f6b"}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.637+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"admin.system.version","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.651+00:00"},"s":"I", "c":"COMMAND", "id":20459, "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"4.4"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.672+00:00"},"s":"I", "c":"STORAGE", "id":20536, "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
mongo | {"t":{"$date":"2020-10-02T03:49:30.708+00:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"local.startup_log","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"5e85090f-6e5b-4e85-ae54-6e2bb96a7ea3"}},"options":{"capped":true,"size":10485760}}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.775+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"local.startup_log","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.788+00:00"},"s":"I", "c":"FTDC", "id":20625, "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.805+00:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.817+00:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.817+00:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.906+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"LogicalSessionCacheReap","msg":"Slow query","attr":{"type":"command","ns":"config.system.sessions","command":{"listIndexes":"system.sessions","cursor":{},"$db":"config"},"numYields":0,"ok":0,"errMsg":"ns does not exist: config.system.sessions","errName":"NamespaceNotFound","errCode":26,"reslen":134,"locks":{"ReplicationStateTransition":{"acquireCount":{"w":2}},"Global":{"acquireCount":{"r":2}},"Database":{"acquireCount":{"r":2}},"Collection":{"acquireCount":{"r":1}},"Mutex":{"acquireCount":{"r":2}}},"protocol":"op_msg","durationMillis":107}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.907+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"LogicalSessionCacheRefresh","msg":"Slow query","attr":{"type":"command","ns":"config.system.sessions","command":{"listIndexes":"system.sessions","cursor":{},"$db":"config"},"numYields":0,"ok":0,"errMsg":"ns does not exist: config.system.sessions","errName":"NamespaceNotFound","errCode":26,"reslen":134,"locks":{"ReplicationStateTransition":{"acquireCount":{"w":2}},"Global":{"acquireCount":{"r":2}},"Database":{"acquireCount":{"r":2}},"Collection":{"acquireCount":{"r":1}},"Mutex":{"acquireCount":{"r":2}}},"protocol":"op_msg","durationMillis":110}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.944+00:00"},"s":"I", "c":"CONTROL", "id":20712, "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
mongo | {"t":{"$date":"2020-10-02T03:49:30.952+00:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"LogicalSessionCacheRefresh","msg":"createCollection","attr":{"namespace":"config.system.sessions","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"54495daa-2111-4041-86bc-49fd0bf83159"}},"options":{}}}
mongo | {"t":{"$date":"2020-10-02T03:49:31.095+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:31.096+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"lsidTTLIndex","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}}
mongo | {"t":{"$date":"2020-10-02T03:49:31.097+00:00"},"s":"I", "c":"COMMAND", "id":51803, "ctx":"LogicalSessionCacheRefresh","msg":"Slow query","attr":{"type":"command","ns":"config.system.sessions","command":{"createIndexes":"system.sessions","indexes":[{"key":{"lastUse":1},"name":"lsidTTLIndex","expireAfterSeconds":1800}],"writeConcern":{},"$db":"config"},"numYields":0,"reslen":114,"locks":{"ParallelBatchWriterMode":{"acquireCount":{"r":5}},"ReplicationStateTransition":{"acquireCount":{"w":5}},"Global":{"acquireCount":{"r":2,"w":3}},"Database":{"acquireCount":{"r":2,"w":3}},"Collection":{"acquireCount":{"r":3,"w":2}},"Mutex":{"acquireCount":{"r":6}}},"flowControl":{"acquireCount":1,"timeAcquiringMicros":2},"storage":{},"protocol":"op_msg","durationMillis":177}}
photo-gallery | {"v":0,"level":30,"name":"newrelic_bootstrap","hostname":"fd351c4cfb95","pid":1,"time":"2020-10-02T03:49:28.963Z","msg":"Using New Relic for Node.js. Agent version: 6.13.0; Node version: v10.15.3."}
photo-gallery | {"v":0,"level":30,"name":"newrelic_bootstrap","hostname":"fd351c4cfb95","pid":1,"time":"2020-10-02T03:49:28.983Z","msg":"Module not enabled in configuration; not starting."}
photo-gallery | listening on port 3003
photo-gallery | events.js:174
photo-gallery | throw er; // Unhandled 'error' event
photo-gallery | ^
photo-gallery |
photo-gallery | Error: listen EADDRINUSE: address already in use :::3003
photo-gallery | at Server.setupListenHandle [as _listen2] (net.js:1270:14)
photo-gallery | at listenInCluster (net.js:1318:12)
photo-gallery | at Server.listen (net.js:1405:7)
photo-gallery | at Function.listen (/srv/app/node_modules/express/lib/application.js:618:24)
photo-gallery | at Object.<anonymous> (/srv/app/server/start.js:10:5)
photo-gallery | at Module._compile (internal/modules/cjs/loader.js:701:30)
photo-gallery | at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
photo-gallery | at Module.load (internal/modules/cjs/loader.js:600:32)
photo-gallery | at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
photo-gallery | at Function.Module._load (internal/modules/cjs/loader.js:531:3)
photo-gallery | at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
photo-gallery | at startup (internal/bootstrap/node.js:283:19)
photo-gallery | at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
photo-gallery | Emitted 'error' event at:
photo-gallery | at emitErrorNT (net.js:1297:8)
photo-gallery | at process._tickCallback (internal/process/next_tick.js:63:19)
photo-gallery | at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
photo-gallery | at startup (internal/bootstrap/node.js:283:19)
photo-gallery | at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
photo-gallery | Unable to find New Relic module configuration. A base configuration file
photo-gallery | can be copied from /srv/app/node_modules/newrelic/newrelic.js
photo-gallery | and put at /srv/app/newrelic.js or
photo-gallery | /srv/app/server/newrelic.js.
photo-gallery | If you are not using file-based configuration, please set the environment
photo-gallery | variable `NEW_RELIC_NO_CONFIG_FILE=true`.
photo-gallery | Unable to find New Relic module configuration. A base configuration file
photo-gallery | can be copied from /srv/app/node_modules/newrelic/newrelic.js
photo-gallery | and put at /srv/app/newrelic.js or
photo-gallery | /srv/app/server/newrelic.js.
photo-gallery | If you are not using file-based configuration, please set the environment
photo-gallery | variable `NEW_RELIC_NO_CONFIG_FILE=true`.
photo-gallery | {"v":0,"level":30,"name":"newrelic_bootstrap","hostname":"fd351c4cfb95","pid":1,"time":"2020-10-02T03:49:36.683Z","msg":"Using New Relic for Node.js. Agent version: 6.13.0; Node version: v10.15.3."}
photo-gallery | {"v":0,"level":30,"name":"newrelic_bootstrap","hostname":"fd351c4cfb95","pid":1,"time":"2020-10-02T03:49:36.703Z","msg":"Module not enabled in configuration; not starting."}
photo-gallery | listening on port 3003
photo-gallery | events.js:174
photo-gallery | throw er; // Unhandled 'error' event
photo-gallery | ^
photo-gallery |
photo-gallery | Error: listen EADDRINUSE: address already in use :::3003
photo-gallery | at Server.setupListenHandle [as _listen2] (net.js:1270:14)
photo-gallery | at listenInCluster (net.js:1318:12)
photo-gallery | at Server.listen (net.js:1405:7)
photo-gallery | at Function.listen (/srv/app/node_modules/express/lib/application.js:618:24)
photo-gallery | at Object.<anonymous> (/srv/app/server/start.js:10:5)
photo-gallery | at Module._compile (internal/modules/cjs/loader.js:701:30)
photo-gallery | at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
photo-gallery | at Module.load (internal/modules/cjs/loader.js:600:32)
photo-gallery | at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
photo-gallery | at Function.Module._load (internal/modules/cjs/loader.js:531:3)
photo-gallery | at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
photo-gallery | at startup (internal/bootstrap/node.js:283:19)
photo-gallery | at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
photo-gallery | Emitted 'error' event at:
photo-gallery | at emitErrorNT (net.js:1297:8)
photo-gallery | at process._tickCallback (internal/process/next_tick.js:63:19)
photo-gallery | at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
photo-gallery | at startup (internal/bootstrap/node.js:283:19)
photo-gallery | at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
photo-gallery exited with code 1
我不确定是否新的遗迹也可以是一个原因,但当我评论新的遗迹,我仍然得到同样的问题。
1条答案
按热度按时间vqlkdk9b1#
我找到了解决办法。将dockerfile中的行从
到
开始脚本运行index.js文件。我不是100%确定这是为什么,但这解决了问题。