Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. # Creating a MySQL 5.7 Docker Container
  2.  
  3. ### Prerequesites:
  4. - Docker installed
  5.  
  6. ### Steps
  7.  
  8. 1. Pull the 5.7 MySQL image down:
  9.  
  10. `docker pull mysql/mysql-server:5.7`
  11.  
  12. 2. Create a new container using the image above, giving it a recognizable local name:
  13.  
  14. `docker run --name=NewMySQLContainer -d mysql/mysql-server:5.7`
  15.  
  16. 3. Your container should be up and running, which means you have a MySQL server running
  17.  
  18. Now we need to change the `root` user's password, as one was auto-created for you.
  19.  
  20. First, we must find out what the auto-created password was, then use it to login.
  21.  
  22. Look at the logs for your container using the recognizable local name you gave it:
  23.  
  24. `docker logs NewMySQLContainer`
  25.  
  26. Look for a line that looks like this, and copy the value listed:
  27.  
  28. `[Entrypoint] GENERATED ROOT PASSWORD: _____________________`
  29.  
  30. 4. Now, we need to ask for Docker's help to give us an interactive terminal to log in to MySQL, using the `exec` method:
  31.  
  32. `docker exec -it NewMySQLContainer mysql -u root -p`
  33.  
  34. It will then prompt for the password - paste the value you copied from the last step.
  35.  
  36. 5. Now we need to perform the first of two actions: first, set the `root` user password to a new value that you can remember (or SKIP this step if you prefer the auto-generated value. Not a bad option imo):
  37.  
  38. `ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourNewPassword';`
  39.  
  40. Voila, you have a MySQL server running in a Docker container. Spiffy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement