1

This question has been posted before though I do not understand the answer here: use image-file in docker-compose file

I have an image.tar file in the root of my project (same folder as the docker-compose.yml file) and I want to include it in the services of my docker-compose.yml file so that I only have to run docker compose up for all containers and images to start including the local tar image.

Currently, I am running

docker load -i image.tar 

and then running docker compose up though this does not start the image as per the screenshot below.

Even if it did - having to run this every time I want to start the container is something I want to avoid.

The local image is mt4rest.tar. As you will see from the below images - after loading the image and running docker compose up all the services from docker-compose.yml are in use though the mt4rest.tar is not.

How do I include the local tar file in docker-compose.yml so that I only have to run docker compose up and have all docker compose services start along with the local tar image?

Docker Desktop Containers enter image description here

Docker Desktop Images enter image description here

docker-compose.yml

version: '3.9'

services:  
 
  api:
    build: 
      context: ./backend/backend
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    command:  >
      sh -c   "python3 manage.py makemigrations &&
                python3 manage.py migrate &&
                python3 manage.py wait_for_db &&
                python3 manage.py runserver 0.0.0.0:8000"

    environment:
      - DB_HOST=db
      - DB_NAME=${DATABASE_NAME}
      - DB_USER=${DATABASE_USER}
      - DB_PASS=${DATABASE_PASSWORD}
    depends_on:
      - db
  
  db:
    image: postgres:14.1-alpine
    environment:
    - POSTGRES_DB=${DATABASE_NAME}
    - POSTGRES_USER=${DATABASE_USER}
    - POSTGRES_PASSWORD=${DATABASE_PASSWORD}
    volumes: 
      - pg_data:/var/lib/postgresql/data
  
  redis:
    image: redis:alpine

  celery:
    restart: always
    build:
      context: ./backend/backend
    command: celery -A backend worker -l INFO
    volumes:
      - celery_data:/api
    environment:
      - DB_HOST=db
      - DB_NAME=api
      - DB_USER=${DATABASE_USER}
      - DB_PASS=${DATABASE_PASSWORD}
    depends_on:
      - db
      - redis
      - api


volumes:
  celery_data:
  pg_data:
JessicaRyan
  • 115
  • 3
  • 14
  • As answered in the question you referred: you cannot use an image export tarball as an image directly, you need to load it first. But you don't need to load it every time you launch `docker-compose`, only every time you get a new version of the tarball. But your compose file does not reference the imported image `mt4rest` so cannot use it even after importing the tarball as an image. – zigarn Jul 14 '22 at 08:25
  • Ok so then when looking at docker desktop the fact that the image is listed under images though not marked as "in use" means that it is running? – JessicaRyan Jul 14 '22 at 08:29
  • An image doesn't run. A container based on an image runs (and then the image can be considered as "in use"). The compose file doesn't launch any container based on the image `mt4rest` so the image is not used. – zigarn Jul 14 '22 at 08:32
  • 1
    To use the image you need to set in the compose file a service based on the image `mt4rest:latest` (or `mt4rest:dev`), like the redis service is based on the image `redis:alpine` – zigarn Jul 14 '22 at 08:36

1 Answers1

0

As per the comments on this post from @zigarn:

As answered in the question you referred: you cannot use an image export tarball as an image directly, you need to load it first. But you don't need to load it every time you launch docker-compose, only every time you get a new version of the tarball. But your compose file does not reference the imported image mt4rest so cannot use it even after importing the tarball as an image.

To use the image you need to set in the compose file a service based on the image mt4rest:latest (or mt4rest:dev), like the redis service is based on the image redis:alpine

JessicaRyan
  • 115
  • 3
  • 14