0

I am trying to take a Laravel application that I containerized with Laradock, push the images up to a container registry, pull them down to a second machine, and have it work on the other end.

If you do the following from the terminal ...

# registry prefix
REG=gitlab.test.com:5000/org/dept/web/application-name

# tag images that live only on this workstation
docker tag application-name-mariadb   $REG/mariadb:latest
docker tag application-name-workspace $REG/workspace:latest
docker tag application-name-php-fpm   $REG/php-fpm:latest
docker tag application-name-nginx     $REG/nginx:latest

# push them
docker push $REG/mariadb:latest
docker push $REG/workspace:latest
docker push $REG/php-fpm:latest
docker push $REG/nginx:latest

... You can push the container images up to the container registry, and I figured out a way of backing up the container volumes to tar.gz files by running ...

/* Prepare backups folder                                           */
const backupDir = path.resolve(__dirname, 'backups');
fs.mkdirSync(backupDir, { recursive: true });

/* Process every volume                                             */
candidateVolumes.forEach(vol => {
  const blockers = containersUsing(vol);     // running or stopped

  /* ------------------------- BACKUP --------------------------- */
  console.log(`💾  Backing up volume  ${vol}`);
  try {
    sh(
      `docker run --rm -v ${vol}:/volume -v ${backupDir}:/backup alpine ` +
      `sh -c "tar czf /backup/${vol}.tgz -C /volume ."`
    );
  } catch (err) {
    console.error(`   › Backup error: ${err.message}`);
  }
});

... in Node. On the other end, you can do something similar to restore the container volumes. When I try to docker compose up -d using the docker-compose.yml ...

services:
  # ───────────────── Docker‑in‑Docker (build helper) ──────────────────
  docker-in-docker:
    container_name: application-name-docker-in-docker-1
    image: docker:24-dind
    privileged: true
    environment:
      DOCKER_TLS_CERTDIR: ""
    volumes:
      # Engine layer cache
      - type: volume   # application-name_docker-in-docker
        source: dind_engine
        target: /var/lib/docker
      # Shared project source
      - type: volume   # hash value volume
        source: www
        target: /var/www
      # Internal registry / client certs
      - type: volume
        source: dind_engine
        target: /certs/client

  # ───────────────── Workspace (composer/npm, cron, etc.) ─────────────
  workspace:
    container_name: application-name-workspace-1
    image: gitlab.test.com:5000/org/dept/web/application-name/workspace:latest
    depends_on: [docker-in-docker]
    volumes:
      - type: volume   # project code
        source: www
        target: /var/www
      - type: volume   # certs for private registry access
        source: dind_engine
        target: /certs/client
      - type: volume   # supervisor job definitions
        source: dind_engine
        target: /etc/supervisord.d

  # ───────────────── PHP‑FPM ──────────────────────────────────────────
  php-fpm:
    container_name: application-name-php-fpm-1
    image: gitlab.test.com:5000/org/dept/web/application-name/php-fpm:latest
    depends_on: [workspace]
    volumes:
      - type: volume
        source: www
        target: /var/www
      - type: volume
        source: dind_engine
        target: /certs/client
      # Mount the customised php.ini that lives in the D‑in‑D volume
      - type: volume
        source: dind_engine
        target: /usr/local/etc/php/php.ini
        read_only: true

  # ───────────────── NGINX front‑end ──────────────────────────────────
  nginx:
    container_name: application-name-nginx-1
    image: gitlab.test.com:5000/org/dept/web/application-name/nginx:latest
    depends_on: [php-fpm]
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - type: volume
        source: www
        target: /var/www

  # ───────────────── MariaDB ──────────────────────────────────────────
  mariadb:
    container_name: application-name-mariadb-1
    image: gitlab.test.com:5000/org/dept/web/application-name/mariadb:latest
    ports: ["3306:3306"]
    environment:
      MARIADB_DATABASE:      application-name
      MARIADB_USER:          application-name
      MARIADB_PASSWORD:      secret
      MARIADB_ROOT_PASSWORD: root

# ───────────────────────── External volumes ───────────────────────────
volumes:
  # the DinD engine & misc config/certs
  dind_engine:
    external: true
    name: application-name_docker-in-docker

  # your project source tree (hash‑named volume created by Compose)
  www:
    external: true
    name: 33d09b9dce23b55f46c8c4058a47e069377f9564705f7b68a650826bfeae836e # <- Changed based upon the hash generated

... It doesn't work, though. It ends up generating a new container volume and the nginx container doesn't answer on port 80.

I think that it might not have everything available within the containers and that's why it isn't running right? Does anyone know where things are going wrong?

4
  • 1
    There's a lot of things in this Compose file that aren't typical setups. What is the Docker-in-Docker container doing (it's unusual to need this at all)? You seem to be replacing all of the application code with volumes:; can you delete all of the volumes: blocks so you're using the code built into the image? (The MariaDB container should have a volume so it doesn't lose data if this stack is recreated, but for its data and not its code.) Commented Jun 7 at 10:47
  • 1
    @DavidMaze The base Laradock docker-compose.yml is 2248 lines, and it heavily leverages a 1100-line .env file. I'm sure that I'm doing something wonky in my docker-compose.yml but since my only frame of reference has everything from gearman to pgadmin in it, I'm doing the best with what I have. When you generate the containers using Laradock, it generates the containers: - app-name-docker-in-docker-1 (using DnD) - app-name-mariadb-1 - app-name-nginx-1 - app-name-php-fpm-1 - app-name-workspace-1 The app-name_docker-in-docker volume contains the certs, so I kept the container there. Commented Jun 9 at 16:17
  • @DavidMaze... I know that you need a volume for the MariaDB container so that the data can survive a reboot, but since I can't get localhost to respond at all, I suspect that my problem lies elsewhere in the stack. I am pulling the Docker-in-Docker image from Docker Hub and rebuilding it on the other end. I'm considering sending it to the container repository to see if it helps at all, as well. I miss simple web stacks. :) Commented Jun 9 at 16:28
  • I attempted to make changes to docker-compose.yml (unsuccessfully) and tried overriding specific parts of it with a docker-compose.override.yml file. Neither worked great. By default, Laradock relies on bind mounts. You can verify this fact by spinning up new containers and then deleting the project folder. I tried creating production-docker-compose.yml and adding two lines to my .env file. That got me closer, but I still can't get this to work right. Commented Jun 18 at 21:39

0

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.