12/28/2021

Ubuntu Docker Mysql

51
  1. Ubuntu Docker Mysql Commands

Run init script when Docker with MySQL is ready. I am trying to run a script for initialization of MySQL within a Docker container. I just want to run it once, as it creates the default user for MySQL. /root/mysql-user-setup.sql: USE mysql; CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; GRANT ALL ON. Volumes: my-db: Great, now we can start our container. In your command line or terminal, cd into the directory where you made your docker-compose.yml and from there, run docker-compose up (this.

It is importent to keep data persistent for containers running databases. Docker provides you option to keep database files persistent over the docker volumes or storing files directly on host machine.

Use one of the below options to keep MySQL data persistent even after recreating or deleting docker containers.

Option 1 – Storing MySQL Data on Docker Volumes

The Docker volumes are preferred mechanism by the Docker for storing persistent data of Docker containers. You can easily create a Docker volume on your host machine and attach to a Docker containers.

Let’s create a docker-compose file on your system with the following content.

docker-compose.yml:

2
4
6
8
10
12
14
db:
container_name:db
MYSQL_ROOT_PASSWORD:my_secret_password
MYSQL_USER:db_user
ports:
volumes:

After creating file, just run the below command to launch container.

Docker

Output:

Ubuntu Docker Mysql Commands

In this case the MySQL container creats all files on host machine under ./data/db directory. To view these files, just run below command.

  • Most Viewed News

    • Pi 4 Docker
    • Fallout Mac Download
    • Watch Offline Netflix Mac
    • Nvidia Docker Install Ubuntu
    • Windows 10 Pro Download