Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jay-johnson/259e4ee5f89166e62aae42d792707d46 to your computer and use it in GitHub Desktop.
Save jay-johnson/259e4ee5f89166e62aae42d792707d46 to your computer and use it in GitHub Desktop.
Change the Compose File without having to Rebuild the Container

Clone the Repo

$ git clone https://github.com/jay-johnson/docker-schema-prototyping-with-mysql.git

Start the Composition

$ ./start_composition.sh 
Starting with Docker Compose
Pulling db (jayjohnson/schemaprototyping:latest)...
latest: Pulling from jayjohnson/schemaprototyping
a3ed95caeb02: Pull complete
5989106db7fb: Pull complete
75e2f0ff048c: Pull complete
98d3fe0e5a2b: Pull complete
cb2b06526018: Pull complete
d3f18fb8fd93: Pull complete
dbbbb36603a9: Pull complete
fea73f54e760: Pull complete
590f6232d0c3: Pull complete
7a4d25f8a269: Pull complete
c8dd899cb1db: Pull complete
b2540ace42c3: Pull complete
b5b1828daba4: Pull complete
Digest: sha256:a4df1305df7bb306c3338b365ad945cee1f87d282d6672b331d69f8832856b63
Status: Downloaded newer image for jayjohnson/schemaprototyping:latest
Creating schemaprototyping

Wait for the Container to Initialize and MySQL Connectivity

This script uses the MySQL console to verify connectivity to the container's MySQL database once it is ready. Here is how to run it:

$ ./verify_mysql_user.sh
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

Confirm the Environment Variable's Effect on the Log

$ docker exec -ti schemaprototyping cat /tmp/startcontainer.log 

Preparing MySQL from Dir(/opt/db-loaders)
Waiting on Prepare

Done Preparing MySQL

Flashing and Initializing MySQL

Stop the Composition

$ ./stop_composition.sh 
Stopping with Docker Compose
Stopping schemaprototyping ... done

Change the Environment Variable in the Compose File

$ sed -i 's/REBUILD_DB_ON_START=1/REBUILD_DB_ON_START=0/g' docker-compose.yml 

Start the Composition

$ ./start_composition.sh 
Starting with Docker Compose
Recreating schemaprototyping

Wait for the Container to Restart and MySQL Connectivity again

$ ./verify_mysql_user.sh
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

Confirm the Environment Variable's change resulted in a different log entry

$ docker exec -ti schemaprototyping cat /tmp/startcontainer.log 

Using existing Database in Dir: /var/lib/mysql
Removing first time flag

Tailing the logs for keeping the container open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment