I have small docker-compose
version: '3.8'
services:
solr:
image: solr:8.6.2
container_name: solr
environment:
SOLR_JAVA_HOME: /usr/local/openjdk-11
SOLR_JAVA_MEM: "-Xms1024m -Xmx8192m"
ports:
- "8983:8983"
entrypoint:
- bash
- "-c"
- "precreate-core document; exec solr -f"
command: "cp ./solr/db-data-config.xml /var/solr/data/document/conf/db-data-config.xml"
First I create core - document
Then I want replace default confgiuration
db-data-config
managed-schema
solrconfig
In this path - /var/solr/data/document/conf
What is the best way to do this?
Related
I'm trying to get my head around docker. I got it working with my Rails 6 application, it builds and runs succesful. Now I want to push the application into my docker hub repository.
I'm not quite sure how to do this, because I got 3 containers but in every tutorial I read the people just push one.
That's the output of docker ps -a:
That's my docker-compose.yml:
version: '3'
services:
db:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
env_file:
- .env
ports:
- "5432"
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/webmenue
- bundler_gems:/bundle
- ./docker/database.yml:/webmenue/config/database.yml
- cache:/cache
ports:
- "3000:3000"
env_file:
- .env
environment:
- RAILS_ENV=development
- WEBPACKER_DEV_SERVER_HOST=webpacker
- SPROCKETS_CACHE=/cache
depends_on:
- db
webpacker:
build: .
command: ./bin/webpack-dev-server
volumes:
- .:/webmenue
ports:
- '3035:3035'
environment:
- NODE_ENV=development
- RAILS_ENV=development
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
volumes:
postgres:
bundler_gems:
cache:
I read about the --link flag, but this seems to be deprecated.
So: Do I need to push all containers or is there a way to get them into one container?
That is easy in short as simple as: if you have multiple images, you need to push multiple times ;)
Now the helpful answer, you have 2 images: postgress and your current working directory. Postgress is already an image you download from docker hub, so no need to push it.
As for your other 2 apps, they are currently in one docker file, so only one push is needed.
In your compose file they are both using the build: ., therefore they share the docker image. Let's say you pushed it with: docker push max-kirsch/my-cool-app:1.0.0, you would change the docker compose file to look like this:
version: '3'
services:
db:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
env_file:
- .env
ports:
- "5432"
web:
image: max-kirsch/my-cool-app:1.0.0
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/webmenue
- bundler_gems:/bundle
- ./docker/database.yml:/webmenue/config/database.yml
- cache:/cache
ports:
- "3000:3000"
env_file:
- .env
environment:
- RAILS_ENV=development
- WEBPACKER_DEV_SERVER_HOST=webpacker
- SPROCKETS_CACHE=/cache
depends_on:
- db
webpacker:
image: max-kirsch/my-cool-app:1.0.0
command: ./bin/webpack-dev-server
volumes:
- .:/webmenue
ports:
- '3035:3035'
environment:
- NODE_ENV=development
- RAILS_ENV=development
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
volumes:
postgres:
bundler_gems:
cache:
I think you are confused because you have 2 apps in your compose file that shares the same docker file. And it might be that this confusing is correct. In my personal opinion, you should create them both there ow docker file where only the components are installed that you need. It is hard to be sure without seeing the docker file, but as an example, it does not look like your webpacker needs ruby installed and can start with a simple node image as the base instead of installing node in your ruby image.
I would like to execute a command inside the solr docker image to export metrics.
https://lucene.apache.org/solr/guide/7_3/monitoring-solr-with-prometheus-and-grafana.html
I tried with this :
command:
- solr-demo
- sh ./bin/solr-exporter -p 9854 -b http://localhost:8983/solr
Here is the complete docker-compose
version: '3.7'
volumes:
solr_data: {}
services:
solr:
image: solr:8
ports:
- "8983:8983"
volumes:
- solr_data:/var/solr
command:
- solr-demo
I don't have any errors but the command to launch the exporter is not executed.
The Prometheus way to address this issue is to run the solr-exporter as a separate docker container or side-car and have it scrape the solr server.
version: '3.7'
volumes:
solr_data: {}
services:
solr:
image: solr:8
ports:
- "8983:8983"
volumes:
- solr_data:/var/solr
command:
- solr-demo
solr-exporter:
image: solr:8
ports:
- "9854:9854"
entrypoint:
- "/opt/solr-8.2.0/contrib/prometheus-exporter/bin/solr-exporter"
- "-p"
- "9854"
- "-b"
- "http://solr:8983/solr"
- "-f"
- "/opt/solr-8.2.0/contrib/prometheus-exporter/conf/solr-exporter-config.xml"
- "-n"
- "8"
Using "http://solr:8983/solr" as the target for the exporter makes it scrape the container named solr.
The above exporter commandline was taken verbatim from the docs here, you might want to adjust it depending on your needs.
I am trying to run the following docker-compose file:
version: "3"
services:
db:
image: postgres
container_name: pgsql
environment:
- foo=foo
- bar=bar
volumes:
- ./sql/:/opt/sql
command: bash /opt/sql/create-db.sql
# command: ps -aux
web:
image: benit/debian-web
container_name: web
depends_on:
- db
ports:
- 80:80
volumes:
- ./html:/var/www/html
I am encountering an error with the line:
command: bash /opt/sql/create-db.sql
It is because pgsql service is not started. It can be monitored with command: ps -aux
How can I run my script once pgsql service is started ?
You can use a volume to provide an initialization sql script:
version: "3"
services:
db:
image: postgres
container_name: pgsql
environment:
- foo=foo
- bar=bar
volumes:
- ./sql/:/opt/sql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
web:
image: benit/debian-web
container_name: web
depends_on:
- db
ports:
- 80:80
volumes:
- ./html:/var/www/html
This will work because original Posgresql dockerfile contains a script (that runs after Posrgres has been started) which will execute any *.sql files from /docker-entrypoint-initdb.d/ folder.
By mounting your local volume in that place, your sql files will be run at the right time.
It's actually mentioned in documentation for that image: https://hub.docker.com/_/postgres under the How to extend this image section.
I'm trying to run a script after Cassandra starts that will create the keyspace.
Here's my docker compose:
version: '3.6'
services:
cassandra:
container_name: cassandra
image: bitnami/cassandra:3.11.2
volumes:
- ./cassandra_data:/bitnami
- ./scripts/cassandra_init.sh:/cassandra_init.sh
environment:
- CASSANDRA_USER=${CASSANDRA_USERNAME}
- CASSANDRA_PASSWORD=${CASSANDRA_PASSWORD}
- CASSANDRA_CLUSTER_NAME=Testing
- CASSANDRA_PASSWORD_SEEDER=yes
entrypoint: ["/app-entrypoint.sh"]
command: ["nami","start","--foreground","cassandra","/cassandra_init.sh"]
volumes:
cassandra_data:
["nami","start","--foreground","cassandra"] starts Cassandra. If I start the container without adding my script, it works just fine.
However if I start the container including my script, I get this error after the container starts:
nami ERROR Unknown command '/cassandra_init.sh'
How can I achieve this?
I figured it out.
In docker.compose I had to call the script init.sh and call it:
version: '3.6'
services:
cassandra:
container_name: cassandra
image: bitnami/cassandra:3.11.2
volumes:
- ./cassandra_data:/bitnami
- ./scripts/cassandra_init.sh:/init.sh
environment:
- CASSANDRA_USER=${CASSANDRA_USERNAME}
- CASSANDRA_PASSWORD=${CASSANDRA_PASSWORD}
- CASSANDRA_CLUSTER_NAME=Testing
- CASSANDRA_PASSWORD_SEEDER=yes
entrypoint: ["/app-entrypoint.sh"]
command: ["/init.sh"]
volumes:
cassandra_data:
and the script should look like this:
#!/bin/bash
nami start cassandra
echo "script stuff here to run after cassandra starts"
I am trying to create a mysql database schema during the docker-compose.yml file is getting executed
version: "2"
services:
web:
build: docker
ports:
- "8080:8080"
environment:
- MYSQL_ROOT_PASSWORD=root
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
ports:
- "3306:3306"
links:
- web
onrun:
command: "docker exec -i test_mysql_1 mysql -uroot -proot test <dummy1.sql"
I tried onrun but this is not working .
i am building the first image but pulling the second image from the docker hub.
kindly help in how to execute the following command after the docker-compose up
There is nothing like onrun in docker-compose. It will only bring up the containers and execute the command. Now you have few possible options
Use mysql Image Initialization
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
volumes:
- ./dummy1.sql:/docker-entrypoint-initdb.d/dummy1.sql
ports:
- "3306:3306"
You may your sql files inside /docker-entrypoint-initdb.d inside the container
Use bash script
docker-compose up -d
# Give some time for mysql to get up
sleep 20
docker-compose exec mysql mysql -uroot -proot test <dummy1.sql
Use another docker service to initialize the DB
version: "2"
services:
web:
build: docker
ports:
- "8080:8080"
environment:
- MYSQL_ROOT_PASSWORD=root
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test
ports:
- "3306:3306"
mysqlinit:
image: mysql:latest
volumes:
- ./dummy1.sql:/dump/dummy1.sql
command: bash -c "sleep 20 && mysql -h mysql -uroot -proot test < /dump/dummy1.sql"
You run another service which will init the DB for you, like mysqlinit in the above one
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order.
From https://hub.docker.com/_/mysql/
That is the convenient way how many databases (postgresql, mysql, ...) are initializing themselves on container-creation. You should create a *.sql / *.sh file and bind it via volume into the new container:
db:
image: mysql:latest
volumes:
- ./db/entrypoint:/docker-entrypoint-initdb.d
environment:
- MYSQL_ROOT_PASSWORD=iamgroot
- MYSQL_DATABASE=gotg
This loads all your sql / sh files into the container which are then automatically executed.