I have defined a environment variable JAVA_TOOL_OPTIONS in my yaml file. When I start up my containers with the command "docker-compose -f up" I get the following error:
Picked up JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,address=8010,server=y,suspend=n
Listening for transport dt_socket at address: 8010
Picked up JAVA_TOOL_OPTIONS: -agentlib:jdwp=transport=dt_socket,address=8010,server=y,suspend=n
ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
Error occurred during initialization of VM
agent library failed to init: jdwp
It looks like the JAVA_TOOL_OPTIONS is set twice. Any help will be very much appreciated
Below is my .yaml file:
version: '3.1'
services:
blumeglobal:
build:
context: .
dockerfile: Dockerfile
image: corda-3.2
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10003:10003"
- "10004:10004"
- "10005:10005"
image: corda:3.2
container_name: blumeglobal
volumes:
- ./build/nodes/BlumeGlobal/network-parameters:/opt/corda/network-parameters
- ./build/nodes/BlumeGlobal/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/BlumeGlobal/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/BlumeGlobal/node.conf:/opt/corda/node.conf
- ./build/nodes/BlumeGlobal/cordapps/:/opt/corda/cordapps/
- ./build/nodes/BlumeGlobal/certificates/:/opt/corda/certificates/
networks:
- mynetwork
bestbuy:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10012:10002"
- "10013:10003"
- "10014:10004"
- "10015:10015"
image: corda:3.2
container_name: bestbuy
volumes:
- ./build/nodes/Bestbuy/network-parameters:/opt/corda/network-parameters
- ./build/nodes/Bestbuy/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/Bestbuy/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/Bestbuy/node.conf:/opt/corda/node.conf
- ./build/nodes/Bestbuy/cordapps/:/opt/corda/cordapps/
- ./build/nodes/Bestbuy/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
expeditors:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
- JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8010,server=y,suspend=n
ports:
- "10022:10002"
- "10023:10003"
- "10024:10004"
- "10025:10025"
- "8010:8010"
image: corda:3.2
container_name: expeditors
volumes:
- ./build/nodes/Expeditors/network-parameters:/opt/corda/network-parameters
- ./build/nodes/Expeditors/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/Expeditors/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/Expeditors/node.conf:/opt/corda/node.conf
- ./build/nodes/Expeditors/cordapps/:/opt/corda/cordapps/
- ./build/nodes/Expeditors/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
motorcarrier:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10032:10002"
- "10033:10003"
- "10034:10004"
- "10035:10035"
image: corda:3.2
container_name: motorcarrier
volumes:
- ./build/nodes/DTDC/network-parameters:/opt/corda/network-parameters
- ./build/nodes/DTDC/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/DTDC/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/DTDC/node.conf:/opt/corda/node.conf
- ./build/nodes/DTDC/cordapps/:/opt/corda/cordapps/
- ./build/nodes/DTDC/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
one:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10042:10002"
- "10043:10003"
- "10044:10004"
- "10045:10045"
image: corda:3.2
container_name: one
volumes:
- ./build/nodes/ONE/network-parameters:/opt/corda/network-parameters
- ./build/nodes/ONE/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/ONE/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/ONE/node.conf:/opt/corda/node.conf
- ./build/nodes/ONE/cordapps/:/opt/corda/cordapps/
- ./build/nodes/ONE/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
cisco:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10052:10002"
- "10053:10003"
- "10054:10004"
- "10055:10055"
image: corda:3.2
container_name: cisco
volumes:
- ./build/nodes/Cisco/network-parameters:/opt/corda/network-parameters
- ./build/nodes/Cisco/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/Cisco/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/Cisco/node.conf:/opt/corda/node.conf
- ./build/nodes/Cisco/cordapps/:/opt/corda/cordapps/
- ./build/nodes/Cisco/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
foxconn:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10062:10002"
- "10063:10003"
- "10064:10004"
- "10065:10065"
image: corda:3.2
container_name: foxconn
volumes:
- ./build/nodes/Foxconn/network-parameters:/opt/corda/network-parameters
- ./build/nodes/Foxconn/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/Foxconn/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/Foxconn/node.conf:/opt/corda/node.conf
- ./build/nodes/Foxconn/cordapps/:/opt/corda/cordapps/
- ./build/nodes/Foxconn/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
toshiba:
build:
context: .
dockerfile: Dockerfile
environment:
- JAVA_OPTIONS=-Xmx512m
ports:
- "10072:10002"
- "10073:10003"
- "10074:10004"
- "10075:10075"
image: corda:3.2
container_name: toshiba
volumes:
- ./build/nodes/Toshiba/network-parameters:/opt/corda/network-parameters
- ./build/nodes/Toshiba/persistence.mv.db:/opt/corda/persistence.mv.db
- ./build/nodes/Toshiba/additional-node-infos/:/opt/corda/additional-node-infos/
- ./build/nodes/Toshiba/node.conf:/opt/corda/node.conf
- ./build/nodes/Toshiba/cordapps/:/opt/corda/cordapps/
- ./build/nodes/Toshiba/certificates/:/opt/corda/certificates/
depends_on:
- blumeglobal
networks:
- mynetwork
networks:
mynetwork:
external: true
Below is my Dockerfile
FROM openjdk:8u151-jre-alpine
# Override default value with 'docker build --build-arg BUILDTIME_CORDA_VERSION=version'
# example: 'docker build --build-arg BUILDTIME_CORDA_VERSION=1.0.0 -t corda/node:1.0 .'
ARG BUILDTIME_CORDA_VERSION=3.2-corda
ARG BUILDTIME_JAVA_OPTIONS
ENV CORDA_VERSION=${BUILDTIME_CORDA_VERSION}
ENV JAVA_OPTIONS=${BUILDTIME_JAVA_OPTIONS}
# Set image labels
LABEL net.corda.version = ${CORDA_VERSION} \
maintainer = "<blockchainservice#infosys.com>" \
vendor = "infosys"
RUN apk upgrade --update && \
apk add --update --no-cache bash iputils && \
rm -rf /var/cache/apk/* && \
# Add user to run the app && \
addgroup corda && \
adduser -G corda -D -s /bin/bash corda && \
# Create /opt/corda directory && \
mkdir -p /opt/corda/plugins && \
mkdir -p /opt/corda/logs
# Copy corda jar
ADD --chown=corda:corda https://dl.bintray.com/r3/corda/net/corda/corda/${CORDA_VERSION}/corda-${CORDA_VERSION}.jar /opt/corda/corda.jar
COPY run-corda.sh /run-corda.sh
RUN chmod 777 /opt/corda && chmod +x /run-corda.sh && \
sync && \
chown -R corda:corda /opt/corda
# Expose port for corda (default is 10002) and RPC
EXPOSE 10002
EXPOSE 10003
EXPOSE 10004
EXPOSE 10005 10015 10025 10035 10045 10055 10065 10075
# Working directory for Corda
WORKDIR /opt/corda
ENV HOME=/opt/corda
USER corda
# Start it
CMD ["/run-corda.sh"]
Try another base java image for your dockerfile. (e.g. 'FROM azul/zulu-openjdk:8u192')
Here's an example of what you're trying to do which you can find here: https://github.com/EricMcEvoyR3/corda-docker-compose (you'll notice he doesn't even set the JAVA_TOOL_OPTIONS variables)
You'll also want to note there's a dockerform task in Corda to generate the task for you: https://docs.corda.net/docs/corda-os/4.4/generating-a-node.html#the-dockerform-task
It looks like you're copying over the correct information in the dokcer-compose file, just take another look at these examples and see if you're able to get this to work.
best of luck on the adventure of building blockchain.
Related
There are multiple parts of Compose that deal with environment variables in one sense or another. So how do I pass Environment variables in Compose ( docker-compose )
According to the documentation If you have multiple environment variables, you can substitute them by adding them to a default environment variable file named .env or by providing a path to your environment variables file using the --env-file command line option.
version: '3.9'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- 80:80
- 443:443
restart: always
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
postgres:
container_name: postgres
image: postgres:13-alpine
environment:
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_DATABASE}
volumes:
- ./pgdata:/var/lib/postgresql/data
- ./database/app.sql:/docker-entrypoint-initdb.d/app.sql
restart: always
ports:
- "35000:5432"
networks:
- app_network
app-api:
container_name: app-api
build:
dockerfile: Dockerfile
context: ./app-api
target: production
environment:
- DB_TYPE=${DATABASE_TYPE}
- POSTGRES_HOST=${DB_HOST}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASS=${DB_PASSWORD}
- POSTGRES_DB=${DB_DATABASE}
- POSTGRES_PORT=${DB_PORT}
- APP_PORT=${SERVER_PORT}
- NODE_ENV:production
## AWS
- AWS_S3_ACCESS_KEY=${AWS_S3_ACCESS_KEY}
- AWS_S3_SECRET_ACCESS_KEY=${AWS_S3_SECRET_ACCESS_KEY}
- AWS_S3_BUCKET=${AWS_S3_BUCKET}
- AWS_S3_REGION=${AWS_S3_REGION}
ports:
- "5050:80"
volumes:
- ./pgadmin-data:/var/lib/pgadmin
depends_on:
- postgres
links:
- postgres
networks:
- app_network
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
- PGADMIN_LISTEN_PORT=${PGADMIN_LISTEN_PORT}
restart: always
ports:
- "5400:5400"
depends_on:
- postgres
links:
- postgres
networks:
- app_network
you can use it like this. you have to pass value in each environment variable.
server:
environment:
- AWS_S3_ACCESS_KEY=ABCJQHWEQJHWQ
- AWS_S3_SECRET_ACCESS_KEY=ASKJHDAKJHNAWKLHEN
- AWS_S3_BUCKET=abc-text
- AWS_S3_REGION=eu-west-1
ports:
- "5050:80"
volumes:
- ./pgadmin-data:/var/lib/pgadmin
depends_on:
- postgres
links:
- postgres
networks:
- app_network
When you run docker-compose up, the web service defined above uses the image from the defined Dockerfile. You can verify this with the convert command, which prints your resolved application config to the terminal:
You can use this command to verify if you are pathing the proper environment variables
$ docker compose convert
https://docs.docker.com/compose/environment-variables/
I am trying to set up a docker-pod with laravel, mariadb, nginx, redis and phpmyadmin. The laravel webspace works finde but if i switch to port 10081 like configured in the docker-compose.yml i am not able to login with the root account.
it sais " mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution"
i already tried to configure a "my-network" which links all of the container, but if i understand docker right there is already a "defaul" network which does this. It didnt change the error message anyway.
here is my full docker-compose file
version: "3.8"
services:
redis:
image: redis:6.0-alpine
expose:
- "6380"
db:
image: mariadb:10.4
ports:
- "3307:3306"
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: laravel
volumes:
- db-data:/var/lib/mysql
nginx:
image: nginx:1.19-alpine
build:
context: .
dockerfile: ./docker/nginx.Dockerfile
restart: always
depends_on:
- php
ports:
- "10080:80"
networks:
- default
environment:
VIRTUAL_HOST: cockpit.example.de
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
- ./public:/app/public:ro
php:
build:
target: dev
context: .
dockerfile: ./docker/php.Dockerfile
working_dir: /app
env_file: .env
restart: always
expose:
- "9000"
depends_on:
- composer
- redis
- db
volumes:
- ./:/app
- ./docker/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro
links:
- db:mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 10081:80
restart: always
environment:
PMA_HOST : db
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: secret
depends_on:
- db
#user: "109:115"
links:
- db:mysql
node:
image: node:12-alpine
working_dir: /app
volumes:
- ./:/app
command: sh -c "npm install && npm run watch"
composer:
image: composer:1.10
working_dir: /app
#environment:
#SSH_AUTH_SOCK: /ssh-auth.sock
volumes:
- ./:/app
#- "$SSH_AUTH_SOCK:/ssh-auth.sock"
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
command: composer install --ignore-platform-reqs --no-scripts
volumes:
db-data:
Make sure you have defined all attributes correctly for phpmyadmin container, in the current case there was the absence of -network definition
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin
restart: always
ports:
# 8080 is the host port and 80 is the docker port
- 8080:80
environment:
- PMA_ARBITRARY:1
- PMA_HOST:mysql
- MYSQL_USERNAME:root
- MYSQL_ROOT_PASSWORD:secret
depends_on:
- mysql
networks:
# define your network where all containers are connected to each other
- laravel
volumes:
# define directory path where you shall store your persistent data and config
# files of phpmyadmin
- ./docker/phpmyadmin
Maybe your container cannot start because its volume contains incompatible data. It can happen if you downgrade the version of mysql or mariadb image.
You can resolve the problem if you remove the volume and import the database again. Maybe you have to create a backup first.
Hello I have the following error in my node project:
(node:51) UnhandledPromiseRejectionWarning: Error: getaddrinfo
ENOTFOUND ${DB_HOST}
I'm thinking the problem is that my postgress is not yet started when my project starts
and so I'm not able to think of a solution on how to start my container after my postgres is ready, I read something about dockerize, but I'm not able to imagine how to apply
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 ormconfig.json .env package.json yarn.* ./
USER node
RUN yarn
COPY --chown=node:node . .
EXPOSE 4000
CMD ["yarn", "dev"]
my docker compose:
version: '3.7'
services:
ci-api:
build: .
container_name: ci-api
volumes:
- .:/home/node/api
- /home/node/api/node_modules
ports:
- '${SERVER_PORT}:${SERVER_PORT}'
depends_on:
- ci-postgres
networks:
- ci-network
ci-postgres:
image: postgres:12
container_name: ci-postgres
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
networks:
- ci-network
volumes:
ci-postgres-data:
networks:
ci-network:
driver: bridge
and this is my .env
SERVER_PORT=4000
DB_HOST=ci-postgres
DB_PORT=5432
DB_USER=spirit
DB_PASS=api
DB_NAME=emasa_ci
You can reference the below docker-compose.yml in which depends_on, healthcheck and links are added as web service depends on db service.
Reference:
Postgresql Container is not running in docker-compose file - Why is this?
version: "3"
services:
webapp:
build: .
container_name: webapp
ports:
- "5000:5000"
links:
- postgres
depends_on:
postgres:
condition: service_healthy
postgres:
image: postgres:11-alpine
container_name: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_DB=tmp
- POSTGRES_USER=tmp
- POSTGRES_PASSWORD=tmp_password
volumes: # Persist the db data
- database-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
volumes:
database-data:
Running a docker container with postgres and npm produces this error, while running them separetly
(npm and docker) doesn't. What seems to be the error here?
My docker-compose.yml:
version: "3.5"
services:
db:
image: postgres:12.1
ports:
- 5432:5432
environment:
- FLYWAY_URL=jdbc:postgresql://db:5432/
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypass
- POSTGRES_DB=mydb
volumes:
- ./db/data:/var/lib/postgresql/data
migrate:
image: boxfuse/flyway
entrypoint: ["sh", "-c", "/flyway/wait-for.sh db:5432 -- flyway migrate"]
depends_on:
- db
volumes:
- ./common/migrations/:/flyway/sql:rw
- ./common/scripts/wait-for.sh:/flyway/wait-for.sh:rw
environment:
# - FLYWAY_LOCATIONS=classpath:/common/migrations/
- FLYWAY_PASSWORD=mypass
- FLYWAY_USER=myuser
- FLYWAY_URL=jdbc:postgresql://db:5432/mydb?user=myuser&password=mypass
- FLYWAY_CONNECT_RETRIES=30
networks:
default:
name: mydb-local
services:
example-service:
build: .
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 3000:3000
- 9229:9229
command: npm start
Thing I have checked:
postgresql.conf & pg_hba.conf accepts connections.
DB credentials are correct.
Db is running
I have a docker-compose.yml file that sets up Gitlab, Container Registry and a Gitlab Runner.
version: '2'
services:
redis:
restart: always
image: sameersbn/redis:latest
command:
- --loglevel warning
volumes:
- redis:/var/lib/redis:Z
postgresql:
restart: always
image: sameersbn/postgresql:9.5-3
volumes:
- postgresql:/var/lib/postgresql:Z
environment:
- DB_USER=gitlab
- DB_PASS=password
- DB_NAME=gitlabhq_production
- DB_EXTENSION=pg_trgm
gitlab:
restart: always
image: sameersbn/gitlab:10.1.1
volumes:
- gitlab-data:/home/git/data:Z
- gitlab-logs:/var/log/gitlab
- ./certs:/certs
depends_on:
- redis
- postgresql
ports:
- "80:80"
- "2222:22"
external_links:
- "registry:registry"
environment:
- DEBUG=false
- DB_ADAPTER=postgresql
- DB_HOST=postgresql
- DB_PORT=5432
- DB_USER=gitlab
- DB_PASS=password
- DB_NAME=gitlabhq_production
- REDIS_HOST=redis
- REDIS_PORT=6379
- GITLAB_HTTPS=false # <---
- SSL_SELF_SIGNED=true # <---
- GITLAB_HOST=192.168.99.100 # <---
- GITLAB_PORT=80
- GITLAB_SSH_PORT=2222
- GITLAB_SHELL_SSH_PORT=2222
- GITLAB_RELATIVE_URL_ROOT=
- GITLAB_SECRETS_DB_KEY_BASE=secret
- GITLAB_SECRETS_SECRET_KEY_BASE=secret
- GITLAB_SECRETS_OTP_KEY_BASE=secret
- GITLAB_REGISTRY_ENABLED=true
- GITLAB_REGISTRY_HOST=localhost # <---
- GITLAB_REGISTRY_PORT=4567
- GITLAB_REGISTRY_API_URL=https://localhost:4567/ # Internal address to the registry, will be used by GitLab to directly communicate with API.
- GITLAB_REGISTRY_CERT_PATH=/certs/localhost-auth.crt # <---
- GITLAB_REGISTRY_KEY_PATH=/certs/localhost-auth.key # <---
# Read here --> https://hub.docker.com/r/sameersbn/gitlab-ci-multi-runner/
runner:
restart: always
image: gitlab/gitlab-runner:latest
external_links:
- "gitlab:gitlab" # <---
environment:
- CI_SERVER_URL=http://192.168.99.100:80/ci/
- RUNNER_TOKEN=1XoJuQeyyN3EZxAt7pkn # < ------------------- different every time
- RUNNER_DESCRIPTION=default_runner
- RUNNER_EXECUTOR=shell
registry:
restart: always
image: registry:2.4.1
ports:
- "4567:5000" # <---
volumes:
- registry-data:/var/lib/registry
- ./certs:/certs
external_links:
- "gitlab:gitlab" # <---
environment:
- REGISTRY_LOG_LEVEL=info
- REGISTRY_STORAGE_DELETE_ENABLED=true
- REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry
- REGISTRY_AUTH_TOKEN_REALM=http://localhost/jwt/auth # <---
- REGISTRY_AUTH_TOKEN_SERVICE=container_registry
- REGISTRY_AUTH_TOKEN_ISSUER=localhost
- REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE=/certs/localhost-auth.crt # <---
- SSL_REGISTRY_KEY_PATH=/certs/localhost-auth.key # <---
- SSL_REGISTRY_CERT_PATH=/certs/localhost-auth.crt # <---
- REGISTRY_HTTP_TLS_CERTIFICATE=/certs/localhost-auth.crt # <---
- REGISTRY_HTTP_TLS_KEY=/certs/localhost-auth.key # <---
- REGISTRY_HTTP_SECRET=secret
portainer:
image: portainer/portainer
ports:
- "9000:9000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/opt/portainer:/data"
volumes:
gitlab-data:
gitlab-logs:
postgresql:
redis:
registry-data:
The problem is that the runner is not registered and I have to do it every time manually (not succeeded yet though). I would like to be registered automatically to the Gitlab server with the auto-generated token so I [or the arbitrary dev that would use the docker-compose.yml file] do not care about that.
I am trying to find a way to grab the token and feed it to the runner. Is it possible in any way?
You can either (1) mount your /etc/gitlab-runner directory and keep it persistent or (2) create an entrypoint script that registers the runner every time the container starts.
For example, you may have an entrypoint script like this:
#!/usr/bin/env bash
# entrypoint.sh
gitlab-runner register \
--non-interactive \
--url "${CI_SERVER_URL}/" \
--registration-token "${RUNNER_TOKEN}" \
--executor "${RUNNER_EXECUTOR}" \
--descritpion="${RUNNER_DESCRIPTION}" \
--config="/etc/gitlab-runner/config.toml"
# call original gitlab-runner entrypoint with CMD args
exec /usr/bin/dumb-init /entrypoint "$#"
And a dockerfile for the runner like this:
FROM gitlab/gitlab-runner:v14.8.2
COPY entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]
# Need to redefine original CMD provided by the parent image after setting ENTRYPOINT
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
This is just one way of expressing the solution. In principle, you don't need to custom-build the image -- you could make an equivalent entrypoint: key in your compose file and skip the custom dockerfile.