Not run pmm-agent in docker Mysql 5.7 /8.0

Hi, i have problem run pmm-agent in docker mysql container
my docker-compose file
version: ‘3.9’
services:
mysql:
container_name: mysql57
build:
context: ./images/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: passsuper
MYSQL_USER: ivan
MYSQL_DATABASE: dbinfor
MYSQL_PASSWORD: superpass
command: --default-authentication-plugin=mysql_native_password

my dockerfile for mysql (/images/mysql)
FROM mysql:5.7.33
ADD myconfig.cnf /etc/mysql/conf.d/myconfig.cnf
COPY percona-xtrabackup-80_8.0.22-15-1.buster_amd64.deb percona-xtrabackup-24_2.4.21-1.buster_amd64.deb pmm2-client_2.14.0-6.buster_amd64.deb pmm-agent.yaml /var/
RUN apt-get update && apt-get install -y libdbd-mysql-perl libcurl4-openssl-dev rsync libcurl4 libev4 procps
&& dpkg -i /var/percona-xtrabackup-24_2.4.21-1.buster_amd64.deb && DEBIAN_FRONTEND=noninteractive dpkg -i /var/pmm2-client_2.14.0-6.buster_amd64.deb

COPY entrypointr.sh /
RUN chmod +x /entrypointr.sh
#CMD /entrypointr.sh  
RUN /entrypointr.sh 

entrypointr.sh file
#!/bin/bash
pmm-agent --config-file=/var/pmm-agent.yaml

If I run docker-compose up -d, I get this error

But if I do it differently, then there is no mistake
Remove lines from dockerfile for mysql (/images/mysql)
COPY entrypointr.sh /
RUN chmod +x /entrypointr.sh
#CMD /entrypointr.sh
RUN /entrypointr.sh

Go to dockerterminal and run the command from there, then there are no errors

Actually the question is why can’t I start pmm-agent immediately when starting the container?

Hi Leoni,

RUN commands are executed only at build time so network is not 172.20.1.x yet and pmm-agent can’t connect to pmm-server (172.20.1.2). Also an intermediate container is removed.
So it has to be used CMD command but it this case you are blocking start of mysql demon.

Please consider of adding the command into mysql entrypoint (/usr/local/bin/docker-entrypoint.sh)

1 Like

Thanks for the answer. Did I understand you correctly, should I do this?
my dockerfile
FROM mysql:5.7.33

ENV TZ=Asia/Almaty
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

#Crontab
COPY backup.sh /
RUN chmod +x /backup.sh 

COPY percona-xtrabackup-80_8.0.22-15-1.buster_amd64.deb percona-xtrabackup-24_2.4.21-1.buster_amd64.deb pmm2-client_2.14.0-6.buster_amd64.deb pmm-agent.yaml /var/
RUN apt-get update&& apt-get -y upgrade && apt-get install -y libdbd-mysql-perl libcurl4-openssl-dev rsync libcurl4 libev4 cron procps \
&& dpkg -i /var/percona-xtrabackup-24_2.4.21-1.buster_amd64.deb && DEBIAN_FRONTEND=noninteractive dpkg -i /var/pmm2-client_2.14.0-6.buster_amd64.deb

COPY backup /etc/cron.d/backup
RUN touch /var/log/cron.log && chmod 0644 /etc/cron.d/backup && crontab -u root /etc/cron.d/backup && touch /var/log/cron.log && touch /var/log/cronreboot.log  

RUN sed -i '2icron&& pmm-agent --config-file=/var/pmm-agent.yaml & ' /usr/local/bin/docker-entrypoint.sh

After starting the container, a line will be inserted in the /usr/local/bin/docker-entrypoint.sh file

1 Like
RUN sed -i '2icron&& pmm-agent --config-file=/var/pmm-agent.yaml & ' /usr/local/bin/docker-entrypoint.sh

Yes, it looks correct.

1 Like