How to install Mysql in Docker container?
Apr 02, 2019
ubuntu code snippets docker knowledge base
Install docker
Here is an article about installing docker on ubuntu: How to install docker on ubuntu?
Mysql container run in background, root user's password is "test"
>> docker run --rm -it -e MYSQL_ROOT_PASSWORD=test -d mysql
-d Run container in background and print container ID
--rm Automatically remove the container when it exitsShow running containers
>> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ee2e6c8174d mysql "docker-entrypoint.s…" 9 seconds ago Up 7 seconds 3306/tcp, 33060/tcp condescending_snydermysql shell
>> docker exec -it 8ee2e6c8174d mysql -u root -ptest
mysql: [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 9
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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> Show container configs
Show network settings, attached volumes etc.
Got an idea? Find the perfect domain for it
Our AI domain name generator suggests available names across hundreds of extensions. Free SSL, DNS and Whois privacy included.
>> docker inspect 8ee2e6c8174d
[
{
"Id": "8ee2e6c8174d4138026f1d54addf9aadc7fbe22727c7f1fb9ca996ce5f7601b2",
"Created": "2019-03-28T20:53:46.84185469Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
...
...
...
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "4c9f618087d8f2e6924e7683cfb98055d8cc9a4ec8d0427bd188b5b7c34c0b3f",
"EndpointID": "cd5d96ad898831d3cc2d0941633533fdf8dcc6cdb0564164c49cad1a2399e8bf",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
Connect mysql shell with ip adress
mysql -u root -ptest -h 172.17.0.2
Show running and exited containers
>> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ee2e6c8174d mysql "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 3306/tcp, 33060/tcp condescending_snyder
913f33f5a848 mysql "docker-entrypoint.s…" 12 minutes ago Exited (0) 11 minutes ago jovial_dubinsky
b36cf8b3b664 mysql "docker-entrypoint.s…" 22 minutes ago Exited (1) 22 minutes ago cocky_mcnulty
Show all images
>> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 7bb2586065cd 45 hours ago 477MB
Got an idea? Find the perfect domain for it
Our AI domain name generator suggests available names across hundreds of extensions. Free SSL, DNS and Whois privacy included.