Installer MySQL dans un conteneur Docker : le guide facile
Avr 02, 2019
ubuntu code snippets docker knowledge base
Lancer un conteneur MySQL avec Docker
Pour installer Docker sur Ubuntu, consultez cet article dédié.
Démarrez un conteneur MySQL en arrière-plan. Mot de passe root : test.
docker run --rm -it -e MYSQL_ROOT_PASSWORD=test -d mysql
-d: lance en arrière-plan et affiche l'ID.--rm: supprime le conteneur à l'arrêt.
Vérifier les conteneurs actifs
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ee2e6c8174d mysql "docker-entrypoint.s…" 9s ago Up 7s 3306/tcp, 33060/tcp condescending_snyder
Accéder au shell MySQL
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
mysql>
Examiner la config d'un conteneur
Affiche les réseaux, volumes et autres détails.
docker inspect 8ee2e6c8174d
Extrait :
[
{
"Id": "8ee2e6c8174d4138026f1d54addf9aadc7fbe22727c7f1fb9ca996ce5f7601b2",
"Created": "2019-03-28T20:53:46.84185469Z",
...
"Networks": {
"bridge": {
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
...
}
}
}
]
Se connecter via l'IP du conteneur
mysql -u root -ptest -h 172.17.0.2
Lister tous les conteneurs (actifs ou arrêtés)
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ee2e6c8174d mysql "docker-entrypoint.s…" 2 min ago Up 2 min 3306/tcp, 33060/tcp condescending_snyder
913f33f5a848 mysql "docker-entrypoint.s…" 12 min ago Exited (0) 11 min ago jovial_dubinsky
b36cf8b3b664 mysql "docker-entrypoint.s…" 22 min ago Exited (1) 22 min ago cocky_mcnulty
Afficher toutes les images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 7bb2586065cd 45h ago 477MB