Variable substitution in docker-compose command - variables

I need to pass env variable from file to a command in a docker-compose but it seems impossible.
So I try first with environment var but it doesn't work again. How can I do that?
version: '3'
services:
nginx-service-xxx:
image: service-xxx-nginx:latest
ports:
- 80:80
restart: always
service-xxx:
image: service-xxx:latest
# env_file:
# - db-settings.env
environment:
- PORT=80
- PG-HOST=192.168.0.101
- PG-DATABASE=xxx
- PG-USER=postgres
- PG-PASSWORD=postgres
restart: always
command: python xxx/main.py --port=$$PORT --pg-host=$$PG-HOST --pg-database=$$PG-DATABASE --pg-user=$$PG-USER --pg-password=$$PG-PASSWORD

try to move the complexity of the command to a docker entry point.
First, you need to add the following entry point to your project (make it executable)
#!/bin/bash -e
case $1 in
web)
python xxx/main.py --port=$PORT --pg-host=$PG-HOST --pg-database=$PG-DATABASE --pg-user=$PG-USER --pg-password=$PG-PASSWORD
;;
*)
exec "$#"
;;
esac
exit 0
update the docker file for your service
From base-image
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
update compose
version: '3'
services:
nginx-service-xxx:
image: service-xxx-nginx:latest
ports:
- 80:80
restart: always
service-xxx:
image: service-xxx:latest
environment:
- PORT=80
- PG-HOST=192.168.0.101
- PG-DATABASE=xxx
- PG-USER=postgres
- PG-PASSWORD=postgres
restart: always
command: web

Related

How to configure Jaeger agent to send traces to collector on another server

I'm trying to use Jaeger to manage tracing system. Docker is running locally "all-in-one" image with application (on the same host) without any issues. My question is how to configure jaeger agent on host1 that would send traces jaeger collector on another host2. Host2 is configured with "all-in-one". I can see Jaeger UI on host2 but it doesn't seem getting any traces from host1.
Configure tracer:
var configuration = new Configuration("service-name")
.withSampler(Configuration.SamplerConfiguration.fromEnv())
.withReporter(Configuration.ReporterConfiguration.fromEnv());
GlobalTracer.registerIfAbsent(configuration.getTracer());
return openTracer;
Added environment variables in yaml file on host1:
-e JAEGER_AGENT_HOST=jaeger.hostname.com \
-e JAEGER_AGENT_PORT=6831 \
Added jaeger image in yaml file on host2:
$ docker run -d --name jaeger \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 9411:9411 \
jaegertracing/all-in-one:latest
Any suggestions will be appreciated.
In my case.
Host2
version: '2'
services:
hotrod:
image: jaegertracing/example-hotrod:1.28
ports:
- '8080:8080'
- '8083:8083'
command: ["-m","prometheus","all"]
environment:
- JAEGER_AGENT_HOST=jaeger-agent
- JAEGER_AGENT_PORT=6831
- JAEGER_SAMPLER_TYPE=remote
- JAEGER_SAMPLING_ENDPOINT=http://jaeger-agent:5778/sampling
depends_on:
- jaeger-agent
jaeger-collector:
image: jaegertracing/jaeger-collector:1.28
command:
- "--cassandra.keyspace=jaeger_v1_dc1"
- "--cassandra.servers=cassandra"
- "--collector.zipkin.host-port=9411"
- "--sampling.initial-sampling-probability=.5"
- "--sampling.target-samples-per-second=.01"
environment:
- SAMPLING_CONFIG_TYPE=adaptive
ports:
- "14269:14269"
- "14268:14268"
- "14250:14250"
- "9411:9411"
restart: on-failure
depends_on:
- cassandra-schema
jaeger-query:
image: jaegertracing/jaeger-query:1.28
command: ["--cassandra.keyspace=jaeger_v1_dc1", "--cassandra.servers=cassandra"]
ports:
- "16686:16686"
- "16687"
restart: on-failure
depends_on:
- cassandra-schema
jaeger-agent:
image: jaegertracing/jaeger-agent:1.28
command: ["--reporter.grpc.host-port=jaeger-collector:14250"]
ports:
- "5775:5775/udp"
- "6831:6831/udp"
- "6832:6832/udp"
- "5778:5778"
restart: on-failure
depends_on:
- jaeger-collector
cassandra:
image: cassandra:4.0
cassandra-schema:
image: jaegertracing/jaeger-cassandra-schema:1.28
depends_on:
- cassandra
host1 is
version: '2'
services:
jaeger-agent:
image: jaegertracing/jaeger-agent:1.28
command: ["--reporter.grpc.host-port=host2:14250"]
ports:
- "5775:5775/udp"
- "6831:6831/udp"
- "6832:6832/udp"
- "5778:5778"
restart: on-failure
it works well for me

Building your own docker images of SeleniumHQ/docker-selenium

I'm not sure if it is a bug or just me being stupid but here is the case.
I want to build my image based on StandaloneChromeDebug. Following the Wiki:
Pull the repo.
Generate image:
$ make standalone_chrome_debug
Build the Dockerfile to insure that no errors arise:
$ docker build --no-cache etc/docker-selenium/StandaloneChromeDebug/
Set up my image to the docker-compose.yml like:
selenium-hub:
container_name: selenium-hub
build: ./etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
And... nothing. The container is running (no errros) but Selenium doesn't work, container log is empty, /opt/ folder is empty. What am i doing wrong? How to debug the thing?
Path is wrong, use build: /etc/docker-selenium/StandaloneChromeDebug/ without .
If you try to cd to ./etc/docker-selenium/StandaloneChromeDebug/, you will get an error.
version: "3.5"
services:
selenium-hub:
container_name: selenium-hub
build: /etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
Exapmle:
I feel you are using "build" tag in your compose file rather than "image". Please use "image" tag instead and see if that runs your image correctly.
Also can you please show how you are launching your docker services and what the output is?
Reference to build command

Build failure while trying to use docker-compose build step

I am trying to execute my selenium test on Jenkins node (Ubuntu) which has docker already installed. I added docker-compose build step plugin to my Jenkins project. When i try to build the project, I am getting an error in console -
$ docker-compose -f /home/jenkins/workspace/OM/TestWDM/docker-compose.yml up -d
Build step 'Docker Compose Build Step' changed build result to FAILURE
I am able to execute the project successfully on my local machine. I do have docker-compose.yml file in the root directory. I tried docker ps -a command just to see if it's partially . working, but it's not.
docker-compose file:
version: "3"
services:
selenium-hub:
restart: always
image: selenium/hub:latest
ports:
- "4444:4444"
#selenium-chrome
selenium-chrome:
restart: always
image: selenium/node-chrome-debug
stdin_open: true
links:
- selenium-hub:hub
#selenium-firefox
selenium-firefox:
restart: always
image: selenium/node-firefox-debug
links:
- selenium-hub:hub
chrome:
image: selenium/node-chrome
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
firefox:
image: selenium/node-firefox
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
The reason I am trying to use docker here because I was facing an issue with chrome binary not found without it. My expectation over here was to have my test run successfully on Jenkins node.

Docker-The scale command is deprecated. Use the up command with the --scale flag instead

i want to launch 5 chrome and 5 firefox in docker container. I am using the below command but its giving the following error
The scale command is deprecated. Use the up command with the --scale flag instead.
ERROR: No such service: nodechrome
docker-compose scale nodechrome=5 nodefirefox=5
My docker-compose.yml file
version: '2'
services:
firefoxnode:
image: selenium/node-firefox-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
ports:
- "32772:5900"
chromenode:
image: selenium/node-chrome-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
ports:
- "32773:5900"
hub:
image: selenium/hub
ports:
- "4444:4444"
From where these names came? nodechrome and nodefirefox
Correct your command instead:
from:
docker-compose scale nodechrome=5 nodefirefox=5
to:
docker-compose scale chromenode=5 firefoxnode=5
Try this command:
docker-compose up --scale chrome=5
Verify the Grid by visiting: http://localhost:4444/ui/index.html#/
Refer: Documentation

Update shared volume from data container

Hi guys i'm in this situation, i'd like to deploy the changes in my source code by rebuilding the data container which contains a COPY command for transfer the source in the volume. However when i rebuild the data image and re-run docker-compose i stuck with the old code and the only way to update everything is to remove the webroot volume and recreate it.
Where is the mistake??
server:
build: ./docker/apache
image: server:1.3.16
restart: always
links:
- fpm
ports:
- 80:80 # HTTP
- 443:443 # HTTPS
volumes:
- webroot:/var/www/html:ro
fpm:
build: ./docker/php
image: fpm:1.0
restart: always
links:
- database
volumes:
- webroot:/var/www/html
data:
build:
context: .
dockerfile: dataDockerFile
image: smanapp/data:1.0.0
volumes:
- webroot:/var/www/html
volumes:
webroot:
The named volume webroot is meant to persist data across container restart/rebuilds. The only time the data in the volume is updated from an image is when the volume is created, and the contents of the directory in the image are copied in.
It looks like you mean to use volumes_from which is how you get container to mount volumes defined on data. This is the original "data container" method of sharing data that volumes were designed to replace.
version: "2.1"
services:
server:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
fpm:
image: busybox
volumes_from:
- data
command: ls -l /var/www/html
data:
build: .
image: dply/data
volumes:
- /var/www/html
Note that this has been replaced in version 3 of the compose file so you may need to stick with recreating the volume if you want to use newer features.