Docker Compose Push (multiple services / containers) to Docker Hub

Hello Everybody,

I am kinda newbie into the world of Docker & I have been playing with Docker & Docker Compose for some time. This is my first time posting on Docker forum, so please ignore if my writing is not professional.

I am using Docker Desktop 4.5.1 (74721) on Windows 10.

I want to push multiple services to dockerhub via Docker Compose, but I cannot find a way how will I push the image(s) to Docker hub.

I am able to run docker-compose up -d locally inside my project folder and it works fine generating three containers.

I want to push the same infrastructure to Docker Hub & AWS ECR, only but i cannot fully understand the mechanism. Below I am sharing my Dockerfile & docker-compose.yml files for your reference.

Kindly guide me in the right direction.

Here’s my Dockerfile:

FROM php:8.0-apache

RUN docker-php-ext-install pdo_mysql

WORKDIR /var/www/html/

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

COPY . ./Author-API

WORKDIR /var/www/html/Author-API

RUN composer install

COPY mysites.conf /etc/apache2/sites-available/mysites.conf

RUN a2enmod rewrite &&\
    a2dissite 000-default.conf &&\
    a2ensite mysites.conf &&\
    service apache2 restart

EXPOSE 8085

Here is my docker-compose.yml file:

version: '3.5'

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8090:8085"
    volumes:
      - .:/var/www/html/Author-API
    restart: always
    depends_on:
      - db

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: author_api_db
    volumes:
      - ./database/mysql-data:/var/lib/mysql:rw

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080

volumes:
  mysql-data:

Waiting to hear from you…

Hi

Its not possible to push to multiple registries from docker-compose.
The way to do it is to:

  php:
    build:
      context: .
      dockerfile: Dockerfile
    image: "yourregistry/phpimage:latest"
    ports:
      - "8090:8085"
    volumes:
      - .:/var/www/html/Author-API
    restart: always
    depends_on:
      - db

Then, when you build it ( docker-compose build ) you can also do a docker-compose push, where it will push the images defined in the compose file.

If you want to push to multiple, you need to tag your images, and then do docker push for each of these tags

1 Like

Hello Sir,

Thank You very much for your reply.

I succeeded in pushing container images to docker hub and then doing docker-compose pull everything worked fine.

Now, I need to push these images to AWS ECR.

What are the best practices in that regard? If you could just guide me there.

Thank You. Waiting to hear from you…

Hi again.

Have you checked: Pushing a Docker image - Amazon ECR ?

1 Like

Hello Sir,

I hope you had a wonderful weekend…!!!

Thank you for your reply that saved me a lot of time doing RnDs.

Thank You so much…!!!

Hello Sir,

With your kind help, I have been able to push container images for PHP (Lumen), Adminer & MySQL to AWS ECR.

PHP & Adminer services are running successfully on AWS, but the issue is I am not able to synchronize MySQL service with PHP & Adminer.

While logging into adminer on AWS, I am getting this error message:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve

The configurations for MySQL are mentioned in docker-compose file

version: '3.5'

services:
  php:
    image: "xxxxxxxxxx.dkr.ecr.region.amazonaws.com/img-repository"
    container_name: "php_apache_service"
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8090:8085"
    volumes:
      - .:/var/www/html/Author-API
    restart: always
    depends_on:
      - db

  db:
    image: mysql
    container_name: "mysql_service"
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: author_api_db
    volumes:
      - ./database/mysql-data:/var/lib/mysql:rw

  adminer:
    image: adminer
    container_name: "adminer_service"
    restart: always
    ports:
      - 8080:8080

volumes:
  mysql-data:

Kindly guide me where am i doing wrong configurations.

Waiting to hear from you.

Thank You

I never tried to run ecs services using docker-compose. I run plenty of ECS Services and had to use Service Discovery - Amazon Elastic Container Service for service discovery. The dns resolver inside the ECS Tasks (=“docker” container) use the VPC’s default resolver and not the build-in dns resolver docker provides ootb.

You might want to take a deeper look at Deploying Docker containers on ECS | Docker Documentation.

But to be honest, running containers in ECS (dockerish) is a bigger headache, then runninng them in EKS (kubernetes).

1 Like

Thank you @meyay @terpz for helping me out.

This entire thread became fruitful for me. I have been successful to use docker compose along with docker context.

Thank you so much for your valuable support.