How to extend Dockerimages via docker-compose

Viewed 16

i try to extend my Basic Images from Webdevops. I'll try to add the base-app to my Container that already exists.

Thats my docker-compose:

version: "3"

services:
  base-app:
    image: "webdevops/base-app"
    restart: always
  apache:
    image: "webdevops/php-apache-dev:7.2"
    container_name: apache
    restart: always
    ports:
      - '80:80'
      - '443:443'
    depends_on:
      - mysql
      - base-app
    volumes:
      - "./:/app"

    environment:
      - XDEBUG_MODE=develop,debug
      - XDEBUG_CLIENT_HOST=host.docker.internal
      - XDEBUG_CLIENT_PORT=9003 # 9000=xdebug v2, 9003=v3
      - XDEBUG_REMOTE_CONNECT_BACK=0
      - XDEBUG_REMOTE_AUTOSTART=1
      - XDEBUG_IDE_KEY=docker
      - XDEBUG_START_WITH_REQUEST=trigger
    extra_hosts:
      - "host.docker.internal:host-gateway"
  mysql:
    image: "mysql:latest"
    restart: always
    container_name: mysql
    ports:
      - '3306:3306'
    volumes:
      - './mysql:/var/lib/mysql'
    depends_on:
      - base-app
    environment:
      MYSQL_ROOT_PASSWORD: 'xxxxx'

How to extend my Images with base-app?

1 Answers

You can extend any image using a Dockerfile. For example, you might write a Dockerfile

FROM webdevops/php-apache-dev:7.2
COPY . /app

You can do other steps as required, like RUNning an installation command or setting an alternate CMD you need this image to run. You generally should avoid putting host names or credentials of any sort into the Docker image, leave these as environment: settings in the Compose file.

In your docker-compose.yml file, use a build: block to indicate this image should be built. Do not include an image: line; unless you're specifically planning to push this extended image to a registry; and if you do it must have a different name from the base image.

services:
  apache:
    build: . # _instead of_ image:
    restart: always
    depends_on: [...]
    ports: [...]
    environment: [...]
    # no volumes: since the code is already in the image
    # container_name: is usually unnecessary
Related