Run mysql as root on port 3306 (password: 123)
docker run --name db -d -e MYSQL_ROOT_PASSWORD=123 -p 3306:3306 mysql:latest
Get running docker processes
docker ps
CONTAINER ID IMAGE ... NAMES
36e68b966fd0 mysql:latest ... db
If the image isn't running, you will need to start it, remember its name...
docker start ps
Run that docker image in an interactive terminal
docker exec -it db /bin/bash
login
mysql -uroot -p123
Put these on the local machine image somewhere. You will need to make the shell scripts executable chmod a+x
#!/bin/sh
# Run the MySQL container, with a database named 'users' and credentials
# for a users-service user which can access it.
echo "Starting DB..."
docker run --name db -d \
-e MYSQL_ROOT_PASSWORD=123 \
-e MYSQL_DATABASE=users -e MYSQL_USER=users_service -e MYSQL_PASSWORD=456 \
-p 3306:3306 \
mysql:latest
echo "sleeping..."
sleep 20
# Wait for the database service to start up.
echo "Waiting for DB to start up..."
docker exec db mysqladmin --silent --wait=30 -uusers_service -p456 ping || exit 1
# Run the setup script.
echo "Setting up initial data..."
docker exec -i db mysql -uusers_service -p456 users < setup.sql
create table directory (user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, email TEXT);
insert into directory (email) values ('[email protected]');
insert into directory (email) values ('[email protected]');
insert into directory (email) values ('[email protected]');
insert into directory (email) values ('[email protected]');
insert into directory (email) values ('[email protected]');
#!/bin/sh
# Stop the db and remove the container.
docker stop db && docker rm db