Here is the directory structure
es/
---/elasticsearch/Dockerfile
---docker-compose.yml
here is the dockerfile context
FROM docker.elastic.co/elasticsearch/elasticsearch:7.12.0
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN echo "hello World"
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-phonetic
docker-compose.yml
version: '3.7'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
build: ./elasticsearch/
container_name: es01
ports:
- 9200:9200
- 9300:9300
ulimits:
memlock:
soft: -1
hard: -1
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.type=single-node
#- discovery.seed_hosts=es02,es03
#- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- ./data:/usr/share/elasticsearch/data
networks:
hki_default:
ipv4_address: 172.18.0.120
networks:
hki_default:
external: true
After run docker-compose up , i go into the container command line to
bin/elasticsearch-plugin list
the plugin is still not installed
had tried
build: ./elasticsearch
build: elasticsearch/
build: ./elasticsearch/Dockerfile
but none of about work
Anyone know where is the problem?
Related
I am trying to build this app https://github.com/dwgebler/node-express-example. I want to use it as a template for making a Mongodb http express server. I tried to build the docker compose file in this repo which looks like this:
version: "3.8"
services:
database:
image: mongo
container_name: mongo-database
restart: always
volumes:
- "mongodata:/data/db"
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
container_name: mongo-express
restart: always
ports:
- "8081:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_SERVER: mongo-database
web:
image: node:14-alpine
container_name: node-server
restart: always
user: "node"
ports:
- "9443:443"
volumes:
- "./app:/var/app/"
working_dir: "/var/app"
environment:
NODE_ENV: dev
DB_USER: testdb
DB_PASSWORD: testpwd
DB_NAME: myapp
command: "./wait.sh mongo-database 27017 'npm start'"
volumes:
mongodata:
But when I run the command docker compose up -d in the same directory as the docker-compose.yml file, I get this in the node-server container logs:
SyntaxError: Unexpected number
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47
/var/app/wait.sh:4
shift 2
The wait.sh file where the error is occuring looks like this:
#!/bin/sh
host="$1"
port="$2"
shift 2
cmd="$#"
until nc -z "$host" "$port"; do
>&2 echo "Mongo is unavailable - sleeping"
sleep 1
done
>&2 echo "Mongo started"
exec $cmd
So why is "shift 2" causing this SyntaxError: Unexpected number error? How do I fix this?
The Node image has a script defined in it's ENTRYPOINT that tries to determine if the command passed is something for node or a native Linux command. In your case, it thinks that it's a command for Node, so the script passes your command to Node.
Node then starts running your wait.sh script as a Javascript file and fails.
To get it to run your script, you should override the entrypoint. So instead of
command: "./wait.sh mongo-database 27017 'npm start'"
do
entrypoint: "./wait.sh mongo-database 27017 'npm start'"
This is the portion of the dockerfile that has served us well to date. However, now I need to convert this to be a single node replica set (for transactions to work). I don't want any secondary or arbiter - just the primary node. What am I missing to get this working?
mongo:
image: mongo:4.4.3
container_name: mongo
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: myPass
command: mongod --port 27017
ports:
- '27017:27017'
volumes:
- ./data/mongodb:/data/db
- ./data/mongodb/home:/home/mongodb/
- ./configs/mongodb/mongo-init.sh:/docker-entrypoint-initdb.d/mongo-init.sh:ro
Got it working. I inserted the following into the block in my question above:
hostname: mongodb
volumes:
- ./data/mongodb/data/log/:/var/log/mongodb/
# the healthcheck avoids the need to initiate the replica set
healthcheck:
test: test $$(echo "rs.initiate().ok || rs.status().ok" | mongo -u root -p imagiaRoot --quiet) -eq 1
interval: 10s
start_period: 30s
I was unable to initiate the replica set via the healthcheck. I used the bash script below instead. For Windows users, be sure to call your DB with the name of your computer. For example:
mongodb://DESKTOP-QPRKMN2:27017
run-test.sh
#!/bin/bash
echo "Running docker-compose"
docker-compose up -d
echo "Waiting for DB to initialize"
sleep 10
echo "Initiating DB"
docker exec mongo_container mongo --eval "rs.initiate();"
echo "Running tests"
# test result
if go test ./... -v
then
echo "Test PASSED"
else
echo "Test FAILED"
fi
# cleanup
docker-compose -f docker-compose.test.yml down
docker-compose file
version: '3.8'
services:
mongo:
hostname: $HOST
container_name: mongo_container
image: mongo:5.0.3
volumes:
- ./test-db.d
expose:
- 27017
ports:
- "27017:27017"
restart: always
command: ["--replSet", "test", "--bind_ip_all"]
This forum post was very helpful: https://www.mongodb.com/community/forums/t/docker-compose-replicasets-getaddrinfo-enotfound/14301/4
Hello i'm new to docker and linux and i don't know how to run a script for my docker to run after my postgress
this is my script:
until psql -c '\l'; do
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is unavailable - sleeping"
sleep 1
done
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"
exec ${#}
my docker file :
FROM node:lts-alpine
RUN mkdir -p /home/node/api/node_modules && chown -R node:node /home/node/api
WORKDIR /home/node/api
COPY wait-pg.sh ormconfig.json .env package.json yarn.* ./
USER node
RUN yarn
COPY --chown=node:node . .
EXPOSE 4000
RUN chmod +x /wait-pg.sh
CMD ["yarn", "dev"]
my docker compose:
version: '3.7'
services:
db-pg:
image: postgres:12
container_name: db-pg
ports:
- '${DB_PORT}:5432'
environment:
ALLOW_EMPTY_PASSWORD: 'no'
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${DB_NAME}
volumes:
- ci-postgres-data:/data
ci-api:
build: .
container_name: ci-api
volumes:
- .:/home/node/api
- /home/node/api/node_modules
ports:
- '${SERVER_PORT}:${SERVER_PORT}'
depends_on:
- db-pg
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '5'
volumes:
ci-postgres-data:
If someone can help me like I would in my docker compose and in my dockerfile.
I would like to know how I can add my script to my docker file and docker compose
Check the below Dockerfile
FROM node:lts-alpine
RUN mkdir -p /home/node/api/node_modules && chown -R node:node /home/node/api
WORKDIR /home/node/api
COPY wait-pg.sh ormconfig.json .env package.json yarn.* ./
USER node
RUN yarn
COPY --chown=node:node . .
EXPOSE 4000
CMD ["yarn", "dev"]
Please try the below docker-compose.yml in which depends_on, healthcheck and links are added as web service depends on db service.
version: "2.1"
services:
ci-api:
build: .
container_name: ci-api
volumes:
- .:/home/node/api
- /home/node/api/node_modules
ports:
- '${SERVER_PORT}:${SERVER_PORT}'
links:
- db-pg
depends_on:
- db-pg
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '5'
db-pg:
image: postgres:12
container_name: db-pg
ports:
- '${DB_PORT}:5432'
environment:
ALLOW_EMPTY_PASSWORD: 'no'
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${DB_NAME}
volumes:
- ci-postgres-data:/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
volumes:
ci-postgres-data:
MongoDB docker-entrypoint ignoring custom script for creating user and database.
I've tried on many ways. Here is one of my configuration.
Solution 1
docker-compose.yml (version 1)
version: '3.2'
services:
erste-mongodb:
build:
context: .
dockerfile: mongodb.dockerfile
image: erste/lts:mongodb
#environment:
# MONGO_INITDB_ROOT_USERNAME: "root"
# MONGO_INITDB_ROOT_PASSWORD: "toor"
volumes:
- ./data/mongo-data:/data/db
# - ./data/mongo-init:/docker-entrypoint.d/
ports:
- "27017:27017"
networks:
- mynet
networks:
mynet:
dockerfile
FROM mongo:latest
COPY ./data/mongo-init/mongo-init.sh /docker-entrypoint.d/
Solution 2
docker-compose.yml (version 2)
version: '3.2'
services:
erste-mongodb:
build:
context: .
dockerfile: mongodb.dockerfile
image: erste/lts:mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: "root"
MONGO_INITDB_ROOT_PASSWORD: "toor"
volumes:
- ./data/mongo-data:/data/db
- ./data/mongo-init:/docker-entrypoint.d/
ports:
- "27017:27017"
networks:
- mynet
networks:
mynet:
dockerfile
FROM mongo:latest
Here is my init script:
mongo-init.sh
#!/bin/bash
echo "Creating users..."
mongo --eval "db.createUser({user: 'revision', pwd: 'rev123',roles: [{role: 'dbOwner', db: 'ebmn_log'}]});"
mongo -u revision -p rev123 --eval "db = db.getSiblingDB('ebmn_log');
db.createCollection('journal')";
echo "Finishing with users"
Does anyone have an idea how to run initialization script.
Thank you in advance.
The problem was that I have used ./data/mongo-init:/docker-entrypoint.d/ instead of ./data/mongo-init:/docker-entrypoint-initdb.d/.
I have changed that and it works like charm.
P.S. Instead of sh script is always better to use pure js.
I can't find the way to execute the following commands from a docker-compose.yml file:
rails db:setup
rails db:init_data.
I tried to do that as follows and it failed:
version: '3'
services:
web:
build: .
links:
- database
- redis
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
command: ["rails", "db:setup"]
command: ["rails", "db:init_data"]
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
Any idea on what's going wrong here ? Thank you.
The code source is on the GitHub.
You can do two things in my opinion:
Change command: to the following line, because two commands are not allowed in compose file:
command:
- /bin/bash
- -c
- |
rails db:setup
rails db:init_data
Use supervisord app: supervisord web page
The solution that worked for me was to remove CMD commad from Dockerfile because using command option in docker-compose.yml would have overridden CMD command.
So, Docker file will look like that:
FROM ruby:2.5.1
LABEL maintainer="DECATHLON"
RUN apt-get update -yqq
RUN apt-get install -yqq --no-install-recommends nodejs
COPY Gemfile* /usr/src/app/
WORKDIR /usr/src/app
RUN bundle install
COPY . /usr/src/app/
Then add command option to docker-compose file:
version: '3'
services:
web:
build: .
links:
- database
- redis
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
command:
- |
rails db:reset
rails db:init_data
rails s -p 3000 -b '0.0.0.0'
redis:
image: redis
database:
image: postgres
env_file:
- .env/development/database
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
If the above solution does not work for somebody, there is an alternative solution:
Create a shell script in the project route and name it entrypoint.sh, for example:
#!/bin/bash
set -e
bundle exec rails db:reset
bundle exec rails db:migrate
exec "$#"
Declare entrypoint option in dpcker-compose file:
v
version: '3'
services:
web:
build: .
entrypoint:
- /bin/sh
- ./entrypoint.sh
depends_on:
- database
- redis
ports:
- "3000:3000"
volumes:
- .:/usr/src/app
env_file:
- .env/development/database
- .env/development/web
command: ['./wait-for-it.sh', 'database:5432', '--', 'bundle', 'exec', 'rails', 's', '-p', '3000', '-b', '0.0.0.0']
database:
image: postgres:9.6
env_file:
- .env/development/database
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
I also user wait-for-it script to ensure the DB is started.
Hope this helps. I pushed the modifications to the Github repo. Sorry for some extra letters left in the text before code blocks, - for some unknown reasons, the code markdown didn't work, so I left them to get it working.