Writing A Compose File
Assignment
- Build a basic compose file for a Drupal content management system website. Docker Hub is your friend
- Use the
drupal
image along with thepostgres
image - Use
ports
to expose Drupal on 8080 so you can localhost:8080 - Be sure to set
POSTGRES_PASSWORD
for postgres - Walk through Drupal setup via browser
- Tip: Drupal assumes DB is
localhost
, but it's service name - Extra Credit: Use volumes to store Drupal unique data
Solution
docker-compose.yml
version: '2'
services:
drupal:
image: drupal
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-modules:
drupal-profiles:
drupal-sites:
drupal-themes:
Output
~> docker-compose up
Creating network "composeassignment1_default" with the default driver
Creating volume "composeassignment1_drupal-modules" with default driver
Creating volume "composeassignment1_drupal-sites" with default driver
Creating volume "composeassignment1_drupal-profiles" with default driver
Creating volume "composeassignment1_drupal-themes" with default driver
Pulling drupal (drupal:latest)...
latest: Pulling from library/drupal
aa18ad1a0d33: Already exists
29d5f85af454: Pull complete
eca642e7826b: Pull complete
3638d91a9039: Pull complete
3646a95ab677: Pull complete
628b8373e193: Pull complete
c24a2b2280ed: Pull complete
f968b84cbbbc: Pull complete
c77afd73ce87: Pull complete
863afbb95436: Pull complete
99f381536e92: Pull complete
5e96e9b4935a: Pull complete
ca94deb9c4df: Pull complete
3fcfbed742cf: Pull complete
155d19e058b0: Pull complete
14877041fbe0: Pull complete
30f9174b1d2c: Pull complete
Digest: sha256:a4c996da043dfa943537b7f242c1fef6c10e2505f20dd5dd3866cab34a17a4cb
Status: Downloaded newer image for drupal:latest
Pulling postgres (postgres:latest)...
latest: Pulling from library/postgres
Digest: sha256:317a541c064ec73cb48dedc2fbbb7797dd075303a2d9befcb85641e6ff6bf10f
Status: Downloaded newer image for postgres:latest
Creating composeassignment1_drupal_1 ...
Creating composeassignment1_postgres_1 ...
Creating composeassignment1_drupal_1
Creating composeassignment1_postgres_1 ... done
Attaching to composeassignment1_drupal_1, composeassignment1_postgres_1
drupal_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.2. Set the 'ServerName' directive globally to suppress this message
drupal_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.2. Set the 'ServerName' directive globally to suppress this message
drupal_1 | [Sun Oct 01 15:35:46.598021 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/7.1.10 configured -- resuming normal operations
drupal_1 | [Sun Oct 01 15:35:46.598047 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' postgres_1 | The files belonging to this database system will be owned by user "postgres".
postgres_1 | This user must also own the server process.
postgres_1 |
postgres_1 | The database cluster will be initialized with locale "en_US.utf8".
postgres_1 | The default database encoding has accordingly been set to "UTF8".
postgres_1 | The default text search configuration will be set to "english".
postgres_1 |
postgres_1 | Data page checksums are disabled.
postgres_1 |
postgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres_1 | creating subdirectories ... ok
postgres_1 | selecting default max_connections ... 100
postgres_1 | selecting default shared_buffers ... 128MB
postgres_1 | selecting dynamic shared memory implementation ... posix
postgres_1 | creating configuration files ... ok
postgres_1 | running bootstrap script ... ok
postgres_1 | performing post-bootstrap initialization ... ok
postgres_1 | syncing data to disk ... ok
postgres_1 |
postgres_1 | Success. You can now start the database server using:
postgres_1 |
postgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres_1 |
postgres_1 |
postgres_1 | WARNING: enabling "trust" authentication for local connections
postgres_1 | You can change this by editing pg_hba.conf or using the option -A, or
postgres_1 | --auth-local and --auth-host, the next time you run initdb.
postgres_1 | waiting for server to start....LOG: could not bind IPv6 socket: Cannot assign requested address
postgres_1 | HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
postgres_1 | LOG: database system was shut down at 2017-10-01 15:35:47 UTC
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
postgres_1 | LOG: database system is ready to accept connections
postgres_1 | LOG: autovacuum launcher started
postgres_1 | done
postgres_1 | server started
postgres_1 | ALTER ROLE
postgres_1 |
postgres_1 |
postgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgres_1 |
postgres_1 | LOG: received fast shutdown request
postgres_1 | LOG: aborting any active transactions
postgres_1 | LOG: autovacuum launcher shutting down
postgres_1 | waiting for server to shut down....LOG: shutting down
postgres_1 | LOG: database system is shut down
postgres_1 | done
postgres_1 | server stopped
postgres_1 |
postgres_1 | PostgreSQL init process complete; ready for start up.
postgres_1 |
postgres_1 | LOG: database system was shut down at 2017-10-01 15:35:49 UTC
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
postgres_1 | LOG: database system is ready to accept connections
postgres_1 | LOG: autovacuum launcher started
- We can remove volumes as well as we don't need them.
- This is great option for testing
~> docker-compose down -v
Removing composeassignment1_postgres_1 ... done
Removing composeassignment1_drupal_1 ... done
Removing network composeassignment1_default
Removing volume composeassignment1_drupal-modules
Removing volume composeassignment1_drupal-sites
Removing volume composeassignment1_drupal-profiles
Removing volume composeassignment1_drupal-themes