├── ghost ├── Dockerfile └── wait-for-it.sh ├── docker-compose.yaml └── README.md /ghost/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghost:3.40.2 2 | RUN apt-get update -y && \ 3 | apt-get install -y default-mysql-client 4 | COPY ./wait-for-it.sh /usr/local/bin/wait-for-it.sh 5 | -------------------------------------------------------------------------------- /ghost/wait-for-it.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | host="$1" 6 | shift 7 | cmd="$@" 8 | 9 | until mysql -hmysql -p"3306" -u"${database__connection__user}" -p"${database__connection__password}" -D"${database__connection__database}" ; do 10 | >&2 echo "MySQL is unavailable - sleeping" 11 | sleep 1 12 | done 13 | 14 | >&2 echo "MySQL is up - executing command" 15 | exec "$@" 16 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | volumes: 3 | mysql-volume: 4 | ghost-volume: 5 | 6 | services: 7 | mysql: 8 | image: mysql:5.7 9 | container_name: mysql 10 | volumes: 11 | - mysql-volume:/var/lib/mysql 12 | environment: 13 | MYSQL_ROOT_PASSWORD: root 14 | MYSQL_DATABASE: db 15 | MYSQL_USER: blog-user 16 | MYSQL_PASSWORD: supersecret 17 | 18 | ghost: 19 | build: ./ghost 20 | image: lvthillo/ghost:3.40.2 21 | container_name: ghost 22 | volumes: 23 | - ghost-volume:/var/lib/ghost/content 24 | restart: always 25 | ports: 26 | - 2368:2368 27 | environment: 28 | database__client: mysql 29 | database__connection__host: mysql 30 | database__connection__user: blog-user 31 | database__connection__password: supersecret 32 | database__connection__database: db 33 | depends_on: 34 | - mysql 35 | entrypoint: ["wait-for-it.sh", "mysql", "--", "docker-entrypoint.sh"] 36 | command: ["node", "current/index.js"] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ghost and MySQL in Docker Compose 2 | 3 | This project contains a Ghost container which contains a MySQL-client to connect with a persistent MySQL container. 4 | Environment variables are used to create the database and make the connection. 5 | 6 | ``` 7 | $ git clone https://github.com/lvthillo/docker-ghost.git 8 | $ cd docker-ghost-mysql 9 | $ docker-compose up --build -d 10 | ``` 11 | 12 | Visit http://localhost:2368 or http://localhost:2368/ghost 13 | 14 | screen shot 2018-01-13 at 16 19 37 15 | 16 | Create a user 17 | 18 | screen shot 2018-01-13 at 16 22 13 19 | 20 | Verify if the user exists in MySQL 21 | ``` 22 | $ docker ps 23 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 24 | 55e5ccda1a7f lvthillo/ghost:1.20.0 "wait-for-it.sh mysq…" 3 minutes ago Up 3 minutes 0.0.0.0:2368->2368/tcp ghost 25 | 1e51addc77b6 mysql:5.7 "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 3306/tcp mysql 26 | 27 | $ docker exec -it mysql bash 28 | root@1e51addc77b6:/# mysql -ublog-user -p 29 | Enter password: 30 | Welcome to the MySQL monitor. Commands end with ; or \g. 31 | Your MySQL connection id is 79 32 | Server version: 5.7.20 MySQL Community Server (GPL) 33 | 34 | Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 35 | 36 | Oracle is a registered trademark of Oracle Corporation and/or its 37 | affiliates. Other names may be trademarks of their respective 38 | owners. 39 | 40 | Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 41 | 42 | mysql> show databases; 43 | +--------------------+ 44 | | Database | 45 | +--------------------+ 46 | | information_schema | 47 | | db | 48 | +--------------------+ 49 | 2 rows in set (0.00 sec) 50 | 51 | mysql> use db; 52 | Reading table information for completion of table and column names 53 | You can turn off this feature to get a quicker startup with -A 54 | 55 | Database changed 56 | mysql> show tables; 57 | +------------------------+ 58 | | Tables_in_db | 59 | +------------------------+ 60 | | accesstokens | 61 | | app_fields | 62 | | app_settings | 63 | | apps | 64 | | brute | 65 | | client_trusted_domains | 66 | | clients | 67 | | invites | 68 | | migrations | 69 | | migrations_lock | 70 | | permissions | 71 | | permissions_apps | 72 | | permissions_roles | 73 | | permissions_users | 74 | | posts | 75 | | posts_tags | 76 | | refreshtokens | 77 | | roles | 78 | | roles_users | 79 | | settings | 80 | | subscribers | 81 | | tags | 82 | | users | 83 | | webhooks | 84 | +------------------------+ 85 | 24 rows in set (0.00 sec) 86 | 87 | mysql> SELECT name from users; 88 | +------------+ 89 | | name | 90 | +------------+ 91 | | Tim Cahill | 92 | | Ghost | 93 | +------------+ 94 | 2 rows in set (0.00 sec) 95 | 96 | 97 | --------------------------------------------------------------------------------