1

I am trying to do CI/CD on my Laravel application. In order to do this I have to use Jenkins and one command is php artisan migrate:fresh --seed. That means that I need to use a SQL database in order to achieve this.

I am using Portainer. I have created both a Jenkins image with PHP 8 and Composer in it and also a MySQL image. Both are connected through a network called jenkins-mysql. I created both containers for the images.

I am trying to get access to the MySQL container inside the Jenkins container console. Aka I want to do the migration through the MySQL container inside the Jenkins container.

All I have found on the internet is simply to connect them through a network (I already did) and to install MySQL inside the jenkins container, but I have found problems with it and I much rather go the MySQL container route. I haven't found a way to connect directly to the MySQL container from the Jenkins container console through the network.

As extra context, here are the Dockerfiles for both images:

jenkins:

FROM jenkins/jenkins:lts-jdk11
USER root
RUN apt -y update && apt -y upgrade
RUN apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 wget
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
RUN wget -qO - https://packages.sury.org/php/apt.gpg | apt-key add -
RUN apt -y update
RUN apt install -y php8.0-cli php8.0-common php8.0-opcache php8.0-readline php8.0 libapache2-mod-php8.0 php-common php8.0-xml php8.0-gd php8.0-curl php8.0-zip unzip
RUN apt -y update
RUN wget -O composer-setup.php https://getcomposer.org/installer
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
EXPOSE 8080:8080/tcp
EXPOSE 9010:80/tcp
EXPOSE 50000:50000/tcp

mysql:

FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD root
ENV MYSQL_DATABASE aguas
EXPOSE 3306

1 Answers1

0

As you already realized, you have both of the containers inside same docker network so they can communicate with each other. And now you can "resolve" any of the containers within that network with their docker names. Docker will resolve the right IP for you.

More on that on the link:

matic1123
  • 914
  • 6
  • 15