0

I am quite new working with docker. I tried to set up drupal via docker and docker-compose. So far i got a running instance and installed drupal via the installation script.

No i want to clone repositoires via the Dockerfile, which is a drupal module. So after cloning and rebuilding the module should appear in the admin/modzles page)

So i edited my Dockerfile so it looks like this (the last few lines).

FROM drupal:7-apache

RUN apt-get update && apt-get install -y \
        curl \
        git \
        mysql-client \
        vim \
        wget

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
        php composer-setup.php && \
        mv composer.phar /usr/local/bin/composer && \
        php -r "unlink('composer-setup.php');"

RUN wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/download/0.4.2/drush.phar && \
        chmod +x drush.phar && \
        mv drush.phar /usr/local/bin/drush

RUN rm -rf /var/www/html/*

COPY apache-drupal.conf /etc/apache2/sites-enabled/000-default.conf

WORKDIR /app/web/sites/all/modules
RUN git clone -b <branch> --single-branch \
      https://<deploytoken>:<pw>@<gitlab-address>/<path-to-git-rep>.git \

WORKDIR /app

This is my docker-compose.yml

version: '3'
services:
  db:
    image: mariadb:10.2
    environment:
      MYSQL_DATABASE: drupal
      MYSQL_ROOT_PASSWORD: <pswd>
    volumes:
      - db_data:/var/lib/mysql
    restart: always
  drupal:
    depends_on:
      - db
    build: .
    ports:
      - "80:80"
    volumes:
      - ./app:/app
    restart: always
volumes:
  db_data:

Then i used docker-compose build and docker-compose up. It looks like the repository gets cloned and the latest images is used (no errors) but the repository is not in the folder. What did i do wrong?

  • You ssh'd in and verified no files were there? Did you evaluate standing solutions like Docker4Drupal first? Might save you a ton of time trying to debug Docker if you are new to it. – Kevin Oct 28 at 13:25
  • Drupal itself is working fine. I connected to the site and installed drupal with the installation script. But i cant get the GitLab repository to appear. It is a drupal module, so after rebuilding the image is should appear under admin/modules. – Xyarvius Oct 28 at 13:34
  • Hmm, i am just seeing that i am using a bind mount and not a volume. I am not so sure about the differences and usages of the two. – Xyarvius Oct 28 at 13:36
  • It’s possible there was an error? Bash in and see if you can run the command directly. Anyhow it sounds like a question more focused on Docker. – Kevin Oct 28 at 14:42
1

The way I handle this is creating a gitlab auth.json file and with your token and using a volume mount to put it into the container.

volumes:
  - /Users/${USER}/.composer/auth.json:/home/wodby/.composer/auth.json # composer auth

In some instances I've wanted my ssh keys in there as well for certain operations, but shouldn't be needed for a pull off gitlab. This is just as easy.

volumes:
- /Users/${USER}/.ssh/id_rsa:/home/wodby/.ssh/id_rsa # ssh
  • This is exactly what I do as well. This would be required for private repositories especially if you use composer or other tools inside the container. – Kevin Oct 28 at 18:36
  • Ah, i see. I will try that out. Thanks! – Xyarvius Oct 29 at 8:57
  • I've also seen people using the token in a url like prefix://key:token@gitlab.com/repo.git but i have found this easiest. – Ryan Hartman Nov 1 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.