skip to Main Content

I am correctly trying to pass a container ip address to another

Here is my docker-compose.yml file

 app-phpmyadmin:
   image: phpmyadmin/phpmyadmin
   depends_on:
      - app-mysql
   ports:
      - '80'
   container_name: app-phpmyadmin
   environment:
      PMA_HOST: app-mysql
      PMA_PORT: 3306

  app-mysql:
   image: mysql:8
   container_name: app-mysql
   restart: always
   environment:
     MYSQL_ROOT_PASSWORD: root
     MYSQL_ROOT_HOST: app-phpmyadmin <<<< doesnt work see below why
   ports:
      - 3306

When passing app-phpmyadmin instead of passing the ip it actually writes “app-phpmyadmin” as a string. On selecting use, host from mysql.user the hostname is “app-phpmyadmin” instead of the ip.

Is there a way I can do this in the docker-compose file or would i have to come up with a bash script that does it?

2

Answers


  1. try this

    version: '3'
    services:
     app-phpmyadmin:
       image: phpmyadmin/phpmyadmin
       depends_on:
          - app-mysql
       ports:
         - '8081:80'
       container_name: app-phpmyadmin #name expose at list: docker ps
       hostname: app-phpmyadmin #hostname in network docker
       environment:
          PMA_HOST: app-mysql
          PMA_PORT: 3306
          PMA_USER: "root"
          PMA_PASSWORD: "root"
    
     app-mysql:
       image: mysql:5.7 #downgrade beacause mysql 8 generate error with phpmyadmin. error: caching_sha2_password
       container_name: app-mysql #name expose at list: docker ps
       hostname: app-mysql #hostname in network docker
       restart: always
       environment:
         MYSQL_ROOT_PASSWORD: root
       ports:
          - 3306
    
    
    Login or Signup to reply.
  2. Actually, you can have try to use static network address

    version: '3.4'
    services:
      app-phpmyadmin:
         image: phpmyadmin/phpmyadmin
         depends_on:
            - app-mysql
         ports:
            - '81'
         container_name: app-phpmyadmin
         environment:
           PMA_HOST: app-mysql
           PMA_PORT: 3306
        networks:
          app-net:
            ipv4_address: 10.5.0.5
    
      app-mysql:
        container_name: app-mysql
        image: mysql:8
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: root
          MYSQL_ROOT_HOST: 10.5.0.5
        ports:
          - 3306
        networks:
          app-net:
            ipv4_address: 10.5.0.6
    networks:
      app-net:
        driver: bridge
        ipam:
          config:
            - subnet: 10.5.0.0/16
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search