- .secrets
- .gitignore
- mysql
- src
- .gitignore
- Dockerfile
- src
- docker-compose.yml
- README.md
The .gitignore files ensure folder contents are never published to github. The .gitignore file is the only file in folder published to github
- Login to ssh terminal (swarm server)
- Change directory
cd /opt/docker
- Clone mysql repo
git clone https://github.com/keramsey/mysql.git mysql
- Change to project directory
cd /opt/docker/mysql
- Copy database dump files (sql, sql.gz) to mysql/src folder (/opt/docker/mysql/mysql/src). Multiple dump files will be restored to mysql image in alphanumeric order, by file name
- Create 4 secrets files (MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, MYSQL_USER, MYSQL_PASSWORD)
nano .secrets/mysql_root
nano .secrets/mysql_db
nano .secrets/mysql_usr
nano .secrets/mysql_pw
Note: Add desired secret value to each file before saving - Do not surround values with quotes
mysql_root: MYSQL_ROOT_PASSWORD
mysql_root: MYSQL_DATABASE
mysql_usr: MYSQL_USER
mysql_pw: MYSQL_PASSWORD
- Create network
docker create network --type=overlay mysql-net
- Build docker image using 4 build secrets created in step 5 - update image name and tag as needed
DOCKER_BUILDKIT=1 docker build --no-cache -t "mysql:1.0.0" --secret id=mysql_root,src=/opt/docker/mysql/.secrets/.mysql_root --secret id=mysql_db,src=/opt/docker/mysql/.secrets/.mysql_db --secret id=mysql_usr,src=/opt/docker/mysql/.secrets/.mysql_usr --secret id=mysql_pw,src=/opt/docker/mysql/.secrets/.mysql_pw ./mysql
- Deploy stack service (mysql_mysql)
docker stack deploy -c docker-compose.yml mysql