简体   繁体   中英

docker pull to also get postgres dependency image?

New to Docker

Background: I have written a docker-compose.yml which when run with docker-compose up will build and run nicely on my box. Note: my docker-compose.yml downloads the Postgres image.

version: '3'

services:
  api:
     image: conference_api 
     container_name: conference_api
     build:
       context: .
     ports:
       - 5000:80
     environment:
       ASPNETCORE_ENVIRONMENT: Production
     depends_on:
       - postgres
  postgres:
    image: postgres:9.6.3
    container_name: conference_db
    environment:
      POSTGRES_DB: conference
      POSTGRES_USER: conf_app
      POSTGRES_PASSWORD: docker
    ports:
      - 5432:5432
    volumes:
      - ./db:/docker-entrypoint-initdb.d

I then publish my docker image to docker hub.

On a fresh machine I use docker pull to pull my image and then I run it.

I get errors saying bascially "I can't find the database". The Postgres Image was not also downloaded.

My Question: When I pull my image, how can I get the Postgres image to also download as it is a dependency of my Image.

Use docker-compose pull --include-deps [SERVICE...] .

Per the documentation :

--include-deps Also pull services declared as dependencies

This would require the users of your image to have your docker-compose.yml file.

Another option would be to use docker in docker , so docker-compose.yml would be inside your image where it will execute. However, this appears to be discouraged, even by the developer who made this feature possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM