Answer the question
In order to leave comments, you need to log in
What's wrong with port translation and naming in docker-compose assembly?
Good afternoon,
I did it on the side for Listening to the http server, as a database - mongo, (I tried to build with and without networks, the result is the same):
version: '3.7'
services:
node:
container_name: app_node
build: ./docker/containers/node
volumes:
- ./app:/var/www
- ./volumes/node/nginx/:/var/log/nginx/
ports:
- 3002:3000
working_dir: ${CONTAINER_PATH_HOST}
restart: always
tty: true
networks:
- myapp
mongo:
container_name: app_mongo
image: mongo:latest
ports:
- 27018:27017
networks:
- myapp
networks:
myapp:
driver: bridge
mongoose.connect(
'mongodb://mongo:27018/app',
{
useNewUrlParser: true,
useUnifiedTopology: true
}
)
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
app.get('/', (req, res) => {
res.send({'foo': 'bar'});
});
const port = 3000;
app.listen(port, () => console.log('Server running...'));
docker-compose exec node node server.js;
Answer the question
In order to leave comments, you need to log in
The answer is simple - because you need to connect to mongo as mongo: 27017
27018 - this is for connecting from the outside
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question