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?
volumes:; can you delete all of thevolumes: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.)