Docker build Host Key Verification failed

  composer-php, docker, github, ssh-keys

I am getting Host key verification failed error on this docker file.

SSH credentials are working fine as RUN git clone [email protected]:XXXX/YYY-XXX-YYY-XXX.git step is working fine but when RUN --mount=type=ssh,id=id_rsa RUN php -d memory_limit=2G $(which composer) install --no-progress --no-dev I am getting host key verification failed error.

FROM base as build
    RUN curl https://files.magerun.net/n98-magerun2.phar -o /usr/local/bin/magerun 
        && chmod 755 /usr/local/bin/magerun
    
    # RUN git clone [email protected]:XXXX/YYY-XXX-YYY-XXX.git
    
    ARG SSH_PRIVATE_KEY
    
    RUN mkdir /root/.ssh
    RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa
    RUN chmod 600 /root/.ssh/id_rsa
    
    # make sure your domain is accepted
    RUN touch /root/.ssh/known_hosts
    RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
    
    RUN --mount=type=ssh,id=id_rsa RUN php -d memory_limit=2G $(which composer) install --no-progress --no-dev
    
    USER www-data
    WORKDIR /var/www/html
    
    ARG COMPOSER_AUTH
    
    COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
    RUN composer global require hirak/prestissimo
    
    COPY --chown=www-data composer.json composer.json
    COPY --chown=www-data composer.lock composer.lock
    COPY --chown=www-data  auth.json auth.json
    
    RUN php -d memory_limit=2G $(which composer) install --no-progress --no-dev
    
    COPY --chown=www-data app/etc/config.php app/etc/config.php
    COPY --chown=www-data bin bin

Source: Docker Questions

LEAVE A COMMENT