5

I tried to do a clone via Git on my docker compose, but i'm just started using a docker and i don't know how can i do it. I want to do a download inside de apache (document root) /var/www/html. The line is: command: bash -c "git clone [email protected]:user/project.git"

version: '3.8'

services:
    mysql:
      image: mysql:8.0.21
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      container_name: mysql
      environment:
          - MYSQL_ROOT_PASSWORD=root
          - MYSQL_USER=user
          - MYSQL_PASSWORD=pass
          - MYSQL_MAX_ALLOWED_PACKET=1024M
          - MYSQL_INNODB_BUFFER_POOL_SIZE=1G
          - MYSQL_INNODB_LOG_FILE_SIZE=256M
          - MYSQL_INNODB_LOG_BUFFER_SIZE=256M
      ports:
          - '3361:3360'
      volumes:
          - "./docker/mysql:/docker-entrypoint-initdb.d"
    apache:
      image: php:7.4.11-apache
      restart: always
      container_name: apache
      ports:
        - '8081:80'
        - '443:8443'
      volumes:
        - ./docker/www:/var/www/html
      command: bash -c "git clone [email protected]:user/project.git"
      environment:
        XDEBUG_CONFIG: "remote_enable=1 remote_host=192.168.15.21 remote_port=8081 remote_autostart=1"
      depends_on:
        - mysql
      links:
        - mysql
    phpmyadmin:
      image: phpmyadmin:latest
      restart: always
      container_name: phpmyadmin
      ports:
        - 8080:80
      depends_on:
        - mysql
      environment:
        - PMA_ARBITRARY=1
      volumes:
        - "./docker/phpmyadmin/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php"
3
  • Any error you are getting? Commented Oct 20, 2020 at 4:52
  • @PrateekNaik apache exited with code 127 Commented Oct 20, 2020 at 8:02
  • Especially since you're bind-mounting that directory from the host, you can just run the git command there. You can add some artifacts like this docker-compose.yml file and the Dockerfile you need to build your custom image into the root of the repository as well. Commented Oct 20, 2020 at 12:20

1 Answer 1

6

@GustavoFilgueiras The reason you are encountering an error is because the image php:7.4.11-apache that you are utilizing for your apache service does not come with git preinstalled. Also, based on your feedback, the following assumes you are attempting to connect to a private repo and the SSH key normally utilized is located in the default path ~/.ssh/id_rsa (please update this in docker-compose.yml if not the case). You have two options to resolve it:

  1. (Recommended) Create a new custom image by utilizing php:7.4.11-apache as a base image. This brings the benefit of adding this dependency directly into the image so that startup times do not experience unnecessary delays. To do this, you need to create a Dockerfile within the same directory like so:
FROM php:7.4.11-apache
RUN \
  apt-get update && \
  apt-get install git -y && \
  ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts

Then you may modify your apache service in your docker-compose.yml like so:

    apache:
      build: .
      restart: always
      container_name: apache
      ports:
        - '8081:80'
        - '443:8443'
      volumes:
        - ./docker/www:/var/www/html
        - ~/.ssh/id_rsa:/root/.ssh/id_rsa
      command: bash -c "git clone [email protected]:user/project.git"
      environment:
        XDEBUG_CONFIG: "remote_enable=1 remote_host=192.168.15.21 remote_port=8081 remote_autostart=1"
      depends_on:
        - mysql
      links:
        - mysql
  1. Include multiple commands within your docker-compose.yml. This will not require any additional files but the result adds unnecessary delays in startup times as git dependency will need to be installed each time. For instance, your apache service in your docker-compose.yml could look like this:
    apache:
      image: php:7.4.11-apache
      restart: always
      container_name: apache
      ports:
        - '8081:80'
        - '443:8443'
      volumes:
        - ./docker/www:/var/www/html
        - ~/.ssh/id_rsa:/root/.ssh/id_rsa
      command: 
        - bash
        - -c
        - >
          apt-get update;
          apt-get install git -y;
          ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts;
          git clone [email protected]:user/project.git;
      environment:
        XDEBUG_CONFIG: "remote_enable=1 remote_host=192.168.15.21 remote_port=8081 remote_autostart=1"
      depends_on:
        - mysql
      links:
        - mysql
Sign up to request clarification or add additional context in comments.

9 Comments

It's almost work.... I think i have a problem with my ida_rsa key
apache exited with code 128 apache | Hit:1 security.debian.org/debian-security buster/updates InRelease apache | Hit:2 deb.debian.org/debian buster InRelease apache | Hit:3 deb.debian.org/debian buster-updates InRelease
apache | Reading package lists... apache | Reading package lists... apache | Building dependency tree... apache | Reading state information... apache | git is already the newest version (1:2.20.1-2+deb10u3). apache | The following package was automatically installed and is no longer required:
apache | sensible-utils apache | Use 'apt autoremove' to remove it. apache | 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. apache | Cloning into 'myRepo'...
apache | Host key verification failed. apache | fatal: Could not read from remote repository. apache | apache | Please make sure you have the correct access rights apache | and the repository exists.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.