I could able to run Wiki_js and MongoDB containers using docker-compose. Both are running without any errors.
This is my docker-compose file.
version: '3'
services:
wikidb:
image: mongo:3
expose:
- '27017'
command: '--smallfiles --bind_ip ::,0.0.0.0'
environment:
- 'MONGO_LOG_DIR=/dev/null'
volumes:
- $HOME/mongo/db:/data/db
wikijs:
image: 'requarks/wiki:1.0'
links:
- wikidb
depends_on:
- wikidb
ports:
- '8000:3000'
environment:
WIKI_ADMIN_EMAIL: myemail#gmail.com
volumes:
- $HOME/wiki/config.yml:/var/wiki/config.yml
This is config.yml file. I didn't set up git for this project.
title: Wiki
host: http://localhost
port: 8000
paths:
repo: ./repo
data: ./data
uploads:
maxImageFileSize: 3
maxOtherFileSize: 100
db: mongodb://wikidb:27017/wiki
git:
url: https://github.com/Organization/Repo
branch: master
auth:
type: ssh
username: marty
password: MartyMcFly88
privateKey: /etc/wiki/keys/git.pem
sslVerify: true
serverEmail: marty#example.com
showUserEmail: true
But I cannot load the localhost under the port 8000. Is there a specific reason for this?
Related
I am creating mongo:latest container on my machine using docker-compose.
This is my docker-compose.yaml:
version: '3.6'
services:
backend:
image: backend:1.0.0
container_name: backend
ports:
- '5000:5000'
links:
- mongodb
environment:
NODE_ENV: PRODUCTION
API_PORT: 5000
MONGO_USERNAME: root
MONGO_PASSWORD: rootPassXXX
MONGO_HOST: mongodb
MONGO_PORT: 27017
MONGO_DATABASE: automatic
JWT_TOKEN: Auto
scheduler:
image: scheduler:1.0.0
container_name: scheduler
links:
- mongodb
environment:
NODE_ENV: PRODUCTION
API_PORT: 5000
MONGO_USERNAME: root
MONGO_PASSWORD: rootPassXXX
MONGO_HOST: mongodb
MONGO_PORT: 27017
MONGO_DATABASE: automatic
mongodb:
image: mongo
container_name: mongodb
expose:
- 27017
ports:
- '27017:27017'
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=rootPassXXX
volumes:
- ./conf/mongodb:/data/db
volumes:
autoc:
external: true
networks:
default:
external:
name: automatic
After creating those containers I am receiving from them an error: MongoServerError: Authentication failed.
This is the URI that the application is trying to connect: mongodb://root:rootPassXXX#mongodb:27017/matiautomai.
While trying to investigate what was happening, I was trying to log in to the same mongo container
that initializes with the user name and password variables without the credentials using that way: mongodb://mongodb:27017/automatic, And the application manages to connect to it.
I've reviewed the docs inside the Docker hub and it seems to be that I used the environment variables in the correct way.
What am I missing here?
After seeing your helpful comments, I found the solution for this issue.
I needed to initialize a one-time docker-compose with an initial script that located inside.
docker-compose.yaml:
version: '3.7'
services:
mongodb:
container_name: mongodb
image: mongo:latest
restart: always
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: root-db
volumes:
- ./docker-entrypoint-initdb.d/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
This is the script that located inside ./docker-entrypoint-initdb.d/mongo-init.js:
print('start ~~~~');
db = db.getSiblingDB('yourDBname');
db.createUser(
{
user: 'username',
pwd: 'password',
roles: [{ role: 'readWrite', db: 'yourDBname' }],
},
);
db.createCollection('users');
print('end ~~~~');
After that, you will be able to connect to mongo with the credential you have set in the .js file.
I am trying to connect to mongoDB in a container from a service in another container but getting connection exceptions
I have created a docker-compose.yml
version: "3"
services:
mongo-container:
image: mongo:latest
container_name: "mongo-container"
environment:
- MONGO_INITDB_DATABASE=transactions
ports:
- 27017:27017
networks:
- banking-network
volumes:
- mongodb_data_container:/data/db
transaction-service:
image: transaction-service
container_name: transaction-service
build:
context: transaction-service
dockerfile: local.dockerfile
ports:
- "8083:8083"
depends_on:
- mongo-container
environment:
- MONGO_URL=mongodb://mongo-container:27017/transactions
networks:
- banking-network
networks:
banking-network:
external:
name: banking-network
volumes:
mongodb_data_container:
And in my service application.yml
spring:
application:
name: transaction-service
server:
port: '8083'
mongodb:
connection:
string: mongodb://mongo-container:27017/transactions
database: transactions
So I have a service in one container, and mongoDb in another, both on the same network
d666b7a242fc transaction-service "java -jar /app/tran…" 18 minutes ago Up 18 minutes 0.0.0.0:8083->8083/tcp transaction-service
516d539b29c7 mongo:latest "docker-entrypoint.s…" 18 minutes ago Up 18 minutes 0.0.0.0:27017->27017/tcp mongo-container
The following is MONGO_URL=mongodb://name of container:27017/name of database
- MONGO_URL=mongodb://mongo-container:27017/transactions
Now I can connect to this mongodb from a rest service running on my local host without needing a password and username so I have not added it to my docker-compose. I have seen other examples not using it.
But I am still getting an exception.
It seems this should be straightforward, it has the docker container name, the port and its on the same network. What am I missing.
Thanks for any help.
I found wiring up that does allow one container to talk to another.
The confusing thing, is its totally different to how the docs say to do it
.
in my application.yml I have
spring:
application:
name: transaction-service
data:
mongodb:
database: Transaction
host: mongo-container
port: 27017
server:
port: '8083'
And in my docker-compose
services:
mongo-container:
image: mongo:latest
container_name: "mongo-container"
ports:
- 27017:27017
networks:
- banking-network
volumes:
- mongodb_data_container:/data/db
transaction-service:
image: transaction-service
container_name: transaction-service
build:
context: transaction-service
dockerfile: local.dockerfile
ports:
- "8083:8083"
depends_on:
- mongo-container
links:
- mongo-container
networks:
- banking-network
networks:
banking-network:
external:
name: banking-network
volumes:
mongodb_data_container:
Its confusing that, what should work, what the documents detail does not work.
But this does.
I am trying to create a docker compose file with Spring Boot and Mongo Db but unfortunately I was not successful so far. I checked many pages and videos on the Internet and tried the solutions but it did not work for me so far. Is there anyone else face such issue and solve it somehow?
here is my docker compose file
version: '3'
services:
mongodb:
image: mongo:4.0.7
ports:
- "27017:27017"
expose:
- 27017
networks:
- mynetwork
volumes:
- ./data/mongo:/data/db
api:
build: ../
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prod
depends_on:
- mongodb
networks:
- mynetwork
networks:
mynetwork:
driver: bridge
and here is my application-prod.yml file
server:
port: 8080
spring:
data:
mongodb:
host: mongodb
database: book-retailer
port: 27017
I have 2 servers A and B. When I run filebeat by docker-compose on the server A it's working well. But on the server B I have the following error:
pipeline/output.go:154 Failed to connect to backoff(async(tcp://logstash_ip:5044)): dial tcp logstash_ip:5044: connect: no route to host
So I think I missed some config on the server B. So how can I figure out my problem and fix them.
[Edited] Add filebeat.yml and docker-compose
Notice: I ran filebeat on the server A and got failed, so I tested it on the server B and it is still working. So I guess I have some problems with server config
filebeat.yml
logging.level: error
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/share/filebeat/mylog/**/*.log
processors:
- decode_json_fields:
fields: ['message']
target: 'json'
output.logstash:
hosts: ['logstash_ip:5044']
console.pretty: true
processors:
- add_docker_metadata:
host: 'unix:///host_docker/docker.sock'
docker-compose
version: '3.3'
services:
filebeat:
user: root
container_name: filebeat
image: docker.elastic.co/beats/filebeat:7.9.3
volumes:
- /var/run/docker.sock:/host_docker/docker.sock
- /var/lib/docker:/host_docker/var/lib/docker
- ./logs/progress:/usr/share/filebeat/mylog
- ./filebeat.yml:/usr/share/filebeat/filebeat.yml:z
command: ['--strict.perms=false']
ulimits:
memlock:
soft: -1
hard: -1
stdin_open: true
tty: true
network_mode: bridge
deploy:
mode: global
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '50'
Thanks in advance
Assumptions:
Mentioned docker-compose file is for filebeat "concentration" server
which is running in docker on server B.
Both server are running in same network space and/or are accessible between themselves
Server B as filebeat server have correct firewall setting to accept connection on port 5044 (check with telnet from server A after starting container)
docker-compose (assuming server B)
version: '3.3'
services:
filebeat:
user: root
container_name: filebeat
ports: ##################
- 5044:5044 # <- see open port
image: docker.elastic.co/beats/filebeat:7.9.3
volumes:
- /var/run/docker.sock:/host_docker/docker.sock
- /var/lib/docker:/host_docker/var/lib/docker
- ./logs/progress:/usr/share/filebeat/mylog
- ./filebeat.yml:/usr/share/filebeat/filebeat.yml:z
command: ['--strict.perms=false']
ulimits:
memlock:
soft: -1
hard: -1
stdin_open: true
tty: true
network_mode: bridge
deploy:
mode: global
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '50'
filebeat.yml (assuming both servers)
logging.level: error
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
keepfiles: 7
permissions: 0644
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/share/filebeat/mylog/**/*.log
processors:
- decode_json_fields:
fields: ['message']
target: 'json'
output.logstash:
hosts: ['<SERVER-B-IP>:5044'] ## <- see server IP
console.pretty: true
processors:
- add_docker_metadata:
host: 'unix:///host_docker/docker.sock'
i'm trying to get a connection between 2 Docker container.
The first one is a postgres database and the second one is a jboss.
I'm using ansible and here is my Playbook:
---
- hosts: localhost
tasks:
- name: start postgresql
docker:
name: mypostgres
image: MYIMAGE_POSTGRES
ports:
- 5432:5432
expose:
- 5432:5432
state: started
env:
DB_USER: "user"
DB_PASS: "pass"
DB_NAME: "name"
- name: start jboss
docker:
name: jboss
image: MYIMAGE_JBOSS
ports:
- 1099:1099
expose:
- 1099:1099
state: running
env:
POSTGRES_PORT_5432_TCP_ADDR: "172.17.0.2"
POSTGRES_PORT_5432_TCP_PORT: 5432
HIBERNATE_CREATE_DDL: ""
DB_NAME: "name"
DB_USER: "user"
DB_PASS: "pass"
If i start both docker images, there is no connection between database and jboss.
Is there anything i had missed, in my configuration?
Thanks a lot,
Pascal
You need to link the postgres container to the jboss one. For doing that, use the link option
...
docker:
name: jboss
image: MYIMAGE_JBOSS
ports:
- 1099:1099
expose:
- 1099:1099
links:
-mypostgres
state: running
env:
POSTGRES_PORT_5432_TCP_ADDR: "mypostgres"
POSTGRES_PORT_5432_TCP_PORT: 5432
HIBERNATE_CREATE_DDL: ""
DB_NAME: "name"
DB_USER: "user"
DB_PASS: "pass"
...