Image Building With Compose

Assignment

  • "Building custom drupal image for local testing"
  • Compose isn't just for developers. Testing apps is easy/fun!
  • Maybe you're learning Drupal admin, or are a software tester
  • Start with Compose file from previous assignment
  • Make your Dockerfile and docker-compose.yml

Solution

~> ls
docker-compose.yml Dockerfile

docker-compose.yml

version: '2'

services: 
  drupal:
    image: custom-drupal  # If we remove this line, it creates random name
    build: .   # Build in this directory and use Dockerfile
    ports: 
      - "8080:80"
    volumes: 
      - drupal-modules:/var/www/html/modules
      - drupal-profiles:/var/www/html/profiles
      - drupal-sites:/var/www/html/sites
      - drupal-themes:/var/www/html/themes
  postgres:
    image: postgres
    environment: 
      - POSTGRES_PASSWORD=mypassword
    volumes:
      - drupal-data:/var/lib/postgresql/data

volumes: 
  drupal-data:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:

Dockerfile

FROM drupal:8.2

RUN apt-get update \
    && apt-get install -y git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/themes

RUN git clone --branch 8.x-3.x --single-branch --depth 1 https://git.drupal.org/project/bootstrap.git \
    && chown -R www-data:www-data bootstrap

WORKDIR /var/www/html

Output

~> docker-compose up
Creating network "composeassignment2_default" with the default driver
Creating volume "composeassignment2_drupal-modules" with default driver
Creating volume "composeassignment2_drupal-sites" with default driver
Creating volume "composeassignment2_drupal-profiles" with default driver
Creating volume "composeassignment2_drupal-data" with default driver
Creating volume "composeassignment2_drupal-themes" with default driver
Building drupal
...
  • After it started I went to localhost:8080 and installed Drupal the same as in previous assignment
  • Switched to Appearance and installed the theme I've copied in my build.
  • Everything worked, check screenshots below

  • Tested if changes are persistent
...
C^
Gracefully stopping... (press Ctrl+C again to force)
Stopping composeassignment2_postgres_1 ... done
Stopping composeassignment2_drupal_1 ... done

~> docker-compose down
Removing composeassignment2_postgres_1 ... done
Removing composeassignment2_drupal_1 ... done
Removing network composeassignment2_default

~> docker-compose up
Creating network "composeassignment2_default" with the default driver
Creating composeassignment2_postgres_1 ...
Creating composeassignment2_drupal_1 ...
Creating composeassignment2_drupal_1
Creating composeassignment2_drupal_1 ... done
Attaching to composeassignment2_postgres_1, composeassignment2_drupal_1
  • Checked that the changes were persistent
  • And cleaned up after I finished with assignments (including volumes and images)
~> docker-compose down -v --rmi local
Removing composeassignment2_drupal_1 ... done
Removing composeassignment2_postgres_1 ... done
Removing network composeassignment2_default
Removing volume composeassignment2_drupal-modules
Removing volume composeassignment2_drupal-sites
Removing volume composeassignment2_drupal-profiles
Removing volume composeassignment2_drupal-data
Removing volume composeassignment2_drupal-themes

~> docker image rm custom-drupal
Untagged: custom-drupal:latest
Deleted: sha256:73fc50f328c1746dc7ad012afd2205ce61fcdd87b9c0987e1cc51df8112bbb79
Deleted: sha256:7b20122f66047fdaeedccf6b3a8154d0c223522f61fef1e508faf370dd1be6b8
Deleted: sha256:d7746c2ea0857b4c8eafc94f72ada58121923518007fe772432540e415dc4117
Deleted: sha256:a35e684732c9ba463c39d703c08949dc4562f1b31240f7c490314ea2f58f6f05
Deleted: sha256:50690d4c05f0c9850ffb8021dea948e87fcc0787304500fb29f0bd0af18d254b
Deleted: sha256:b09b8aec0991a5ce70daa8542869e5f723ec88b16e545949301ea038161de3a5

Additional info

  • Great about this way is that we can keep our images and our containers clean
  • That way if we are shooting around the projects we can have more generic containers and our data will stay there when w switched back to this project, etc.

results matching ""

    No results matching ""