How to convert Kafka from docker-run command to docker-compose? - docker

I am building Kafka CDC but following the document, it runs many docker-run commands.
I want to put it all into a docker-compose.yml but I fail at 1 last command I can not convert to
The below are the commands
docker run -d --name postgres \
-p 5432:5432 \
-e POSTGRES_USER=start_data_engineer \
-e POSTGRES_PASSWORD=password debezium/postgres:12
docker run -d --name zookeeper -p 2181:2181 -p 2888:2888 -p 3888:3888 debezium/zookeeper:1.1
docker run -d --name kafka -p 9092:9092 --link zookeeper:zookeeper debezium/kafka:1.1
docker run -d --name connect -p 8083:8083 --link kafka:kafka \
--link postgres:postgres \
-e BOOTSTRAP_SERVERS=kafka:9092 \
-e GROUP_ID=sde_group \
-e CONFIG_STORAGE_TOPIC=sde_storage_topic \
-e OFFSET_STORAGE_TOPIC=sde_offset_topic debezium/connect:1.1
This is the line I can not convert
docker run -it --rm --name consumer --link zookeeper:zookeeper \
--link kafka:kafka debezium/kafka:1.1 \
watch-topic -a bankserver1.bank.holding --max-messages 1 | grep '^{' | jq
Here is my docker-compose.yml so far
version: '2'
services:
zookeeper:
image: debezium/zookeeper
ports:
- 2181:2181
- 2888:2888
- 3888:3888
kafka:
image: debezium/kafka
ports:
- 9092:9092
links:
- zookeeper
environment:
- ZOOKEEPER_CONNECT=zookeeper:2181
postgres:
image: debezium/postgres:9.6
ports:
- "5432:5432"
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
connect:
image: debezium/connect
ports:
- 8083:8083
- 5005:5005
links:
- kafka
- postgres
- zookeeper
environment:
- BOOTSTRAP_SERVERS=kafka:9092
- GROUP_ID=1
- CONFIG_STORAGE_TOPIC=my_connect_configs
- OFFSET_STORAGE_TOPIC=my_connect_offsets
- STATUS_STORAGE_TOPIC=my_source_connect_statuses
consumer:
image: debezium/kafka:1.1
links:
- zookeeper
- kafka
command: watch-topic -a bankserver1.bank.holding --max-messages 1 | grep '^{' | jq
When I run docker-compose up, everything run normally. But the consumer always fail with this output.
The ZOOKEEPER_CONNECT variable must be set, or the container must be linked to one that runs Zookeeper.
consumer_1 | WARNING: Using default BROKER_ID=1, which is valid only for non-clustered installations.
consumer_1 | The ZOOKEEPER_CONNECT variable must be set, or the container must be linked to one that runs Zookeeper.
--- Update
For now I just want to read and shootdown. Making sure it works first.
Later then I will have a source handle those reading stuff.
docker run -it --rm --name consumer --link zookeeper:zookeeper --link kafka:kafka debezium/kafka:1.1 watch-topic -a bankserver1.bank.holding | grep --line-buffered '^{' | <your-file-path>/stream.py > my-output/holding_pivot.txt

Following will work...
The points are
I don't know why, but ZOOKEEPER_CONNECT and KAFKA_BROKER do not be set automatically.
You must break commands into a list.
Finally, pipe command had not run inside container.
version: '2'
services:
zookeeper:
image: debezium/zookeeper
ports:
- 2181:2181
- 2888:2888
- 3888:3888
kafka:
image: debezium/kafka
ports:
- 9092:9092
environment:
- ZOOKEEPER_CONNECT=zookeeper:2181
postgres:
image: debezium/postgres:9.6
ports:
- "5432:5432"
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
connect:
image: debezium/connect
ports:
- 8083:8083
- 5005:5005
environment:
- BOOTSTRAP_SERVERS=kafka:9092
- GROUP_ID=1
- CONFIG_STORAGE_TOPIC=my_connect_configs
- OFFSET_STORAGE_TOPIC=my_connect_offsets
- STATUS_STORAGE_TOPIC=my_source_connect_statuses
consumer:
image: debezium/kafka:1.1
environment:
- ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_BROKER=kafka:9092
command:
- watch-topic
- -a
- bankserver1.bank.holding
- --max-messages
- "1"

the consumer always fail with this output.
As the error says, you need to provide a ZOOKEEPER_CONNECT. However, you should be using entrypoint there, not command.
In any case, I don't know if the Debezium container will have the Python modules for you to pipe into stream.py or what watch-topic does, but you don't need another debezium/kafka container since you can exec into the running one.
docker-compose exec kafka \
bash -c "watch-topic -a bankserver1.bank.holding | grep --line-buffered '^{' | <your-file-path>/stream.py > my-output/holding_pivot.txt"

Related

How to install sonarqube developer edition via Docker?

I’m trying to install Sonarqube Developer Edition server but after installation, in footer page, it shows that it’s the Community Edition that is installed.
Here is my docker command:
docker run -d --name sonarqube --restart=always -p 9000:9000 -e sonar.jdbc.url=<my_jdbc_url> -e sonar.jdbc.username=<my_db_user> -e sonar.jdbc.password=<my_db_password> --network sonarqube_network --volume sonarqube:/opt/sonarqube sonarqube:9.7.1-developer
Thanks for you help !
Can you try:
docker run -d -p 9000:9000 -p 9092:9092 sonarqube:developer
Navigate to http://localhost:9000
Or you may be able pass your variables directly in by running:
docker run -d -e SONAR_TOKEN=<YOUR_TOKEN> -e SONAR_EDITION=developer -p 9000:9000 -p 9092:9092 sonarqube:developer
Maybe I missed something in my script, but otherwise I managed to solve my problem with docker compose
version: "3"
services:
sonarqube:
image: sonarqube:9.7.1-developer
environment:
SONAR_JDBC_URL: <my_jdbc_url>
SONAR_JDBC_USERNAME: <my_db_username>
SONAR_JDBC_PASSWORD: <my_db_password>
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:

What is the equivalent of ‍-h in docker-compose?

I want convert docker run to docker-compose with -h parameter
What is the equivalent of ‍‍‍‍-h in docker-compose?
My docker run command:
docker run --rm -p 8080:80/tcp -p 1935:1935 -p 3478:3478
-p 3478:3478/udp bigbluebutton -h webinar.mydomain.com
My docker-compose
version: "3"
services:
bigbluebutton:
build: .
container_name: "bigbluebutton"
restart: unless-stopped
ports:
- 1935:1935
- 3478:3478
- 3478:3478/udp
- 8080:80
networks:
public:
networks:
public:
external:
name: public
Anything that appears after the docker run image name is the Compose command:.
docker run \
--rm -p 8080:80/tcp -p 1935:1935 \ # Docker options
-p 3478:3478 -p 3478:3478/udp \ # More Docker options
bigbluebutton \ # Image name
-h webinar.mydomain.com # Command
services:
bigbluebutton:
build: .
command: -h webinar.mydomain.com
ports: ['8080:80', '1935:1935', '3478:3478', '3478:3478/udp']

docker-compose environment not the same as Docker -e

I am using docker-compose file and want to add some ENV variables to it, which are not related to redis itself.
redis-master:
environment:
- REDIS_REPLICATION_MODE=master
- ALLOW_EMPTY_PASSWORD=yes
# Domains
- VIRTUAL_HOST=redis-master.xxx.com
- VIRTUAL_PORT=6379
ports:
- '6379:6379'
expose:
- '6379'
image: bitnami/redis:latest
But the problem is that this two ENV were not added to Docker:
VIRTUAL_HOST and VIRTUAL_PORT
If I am doing like
docker run -d -p 6379:6379 --name redis-master -e VIRTUAL_PORT=6379 --expose 6379 -e VIRTUAL_HOST=redis-master.xxx.com bitnami/redis:latest
then I can see this two ENV. Why? What is the difference?
I used your Compose file and I can see the ENVs:
➜ ~ docker-compose up -d
prometherion_redis-master_1 is up-to-date
➜ ~ docker-compose exec redis-master sh
$ env | grep -i virtual
VIRTUAL_HOST=redis-master.xxx.com
VIRTUAL_PORT=6379
If you want to be sure that ENVs are injected: docker inspect <container_id> | jq '.[0].Config.Env' (you need jq installed)

Build from linuxserver\deluge

I'd like to be able to use a Dockerfile with the linuxserver\deluge image but I'm unsure what is the correct way to do this in a docker-compose.yaml file.
docker create \
--name=deluge \
--net=host \
-e PUID=1001 \
-e PGID=1001 \
-e UMASK_SET=<022> \
-e TZ=<timezone> \
-v </path/to/deluge/config>:/config \
-v </path/to/your/downloads>:/downloads \
--restart unless-stopped \
linuxserver/deluge
Can someone help me convert this please so that I can use a Dockerfile
Thanks :)
The following docker-compose.yml file is similar to your command :
version: "3"
services:
deluge:
container_name: deluge
image: linuxserver/deluge
environment:
- PUID=1001
- PGID=1001
- UMASK_SET=<022>
- TZ=<timezone>
volumes:
- </path/to/deluge/config>:/config
- </path/to/your/downloads>:/downloads
restart: unless-stopped
network_mode: host
Documentation is a great place to find the mapping between docker options and docker-compose syntax. Here is a recap of what have been used for this example :
--name => container_name
-e => environment (array of key=value)
-v => volumes (array of volume_or_folder_on_host:/path/inside/container)
--restart <policy> => restart: <policy>
--net=xxxx => network_mode
You can now run docker-compose up to start all your services (only deluge here) instead of your docker run command.

Translate docker run command to docker compose

I'm losing my mind a little here, I think I've translated the command correctly, but I'm getting an error when I try docker-compose up -d
Here's my command, this works - without failure:
sudo docker run -i \
--hostname localhost \
--publish 444:443 --publish 8080:8080 --publish 23:22 \
--name gitlab \
--restart always \
--volume /home/admin/gitlab/config:/etc/gitlab \
--volume /home/admin/gitlab/logs:/var/log/gitlab \
--volume /home/admin/gitlab/data:/var/opt/gitlab \
--volume /home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure \
-e VIRTUAL_HOST=git.example.com
-e VIRTUAL_PORT=8080
gitlab/gitlab-ce:latest
Here's my docker-compose.yml file, which isn't working
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
container_name: gitlab
ports:
- '8080:80'
- '23:22'
- '444:443'
volumes:
- '/home/admin/gitlab/config:/etc/gitlab'
- '/home/admin/gitlab/logs:/var/log/gitlab'
- '/home/admin/gitlab/data:/var/opt/gitlab'
- '/home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure'
environment:
- VIRTUAL_HOST=git.example.ca
- VIRTUAL_PORT=8080
Can you see something that I'm doing wrong?
Add hostname: localhost as you do it in docker run to have
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
container_name: gitlab
hostname: localhost
ports:
- '8080:80'
- '23:22'
- '444:443'
volumes:
- '/home/admin/gitlab/config:/etc/gitlab'
- '/home/admin/gitlab/logs:/var/log/gitlab'
- '/home/admin/gitlab/data:/var/opt/gitlab'
- '/home/admin/gitlab/logs/reconfigure:/var/log/gitlab/reconfigure'
environment:
- VIRTUAL_HOST=git.example.ca
- VIRTUAL_PORT=8080

Resources