Answer a question

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 git@github.com: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 git@github.com: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"

Answers

@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 git@github.com: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 git@github.com: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
Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐