Docker
Most of this can be found on the MySQL website
1. Install docker from repos
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2. Run the hello-world docker container
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
3. Running the above encourages us to run an ubuntu container, which yields this:
$ sudo docker run -it ubuntu bash Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 83ee3a23efb7: Pull complete db98fc6f11f0: Pull complete f611acd52c6c: Pull complete Digest: sha256:703218c0465075f4425e58fac086e09e1de5c340b12976ab9eb8ad26615c3715 Status: Downloaded newer image for ubuntu:latest root@86eecb5ba5a8:/#
You can see you're left with a root shell.
4. More ambitiously, let's try for a full mysql install in a container:
xxx@xxxbox:~$ sudo docker pull mysql/mysql-server:8.0 [sudo] password for xxx: 8.0: Pulling from mysql/mysql-server 501550cfd5c0: Pull complete e0509d775110: Pull complete d5a01765d011: Pull complete 970507e942eb: Pull complete Digest: sha256:0bb21c0f1aa9296e7deafacec5703b80e4d923dfdfcaa2efbe0c8377a8592128 Status: Downloaded newer image for mysql/mysql-server:8.0 docker.io/mysql/mysql-server:8.0
5. Check all your docker images:
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest f63181f19b2f 9 days ago 72.9MB mysql/mysql-server 8.0 d320e74763f4 11 days ago 406MB hello-world latest bf756fb1ae65 13 months ago 13.3kB
6. Now that we have it, we can start it:
docker run --name=mysqli --restart on-failure -d mysql/mysql-server:8.0
This generates a 64-character string; its first 12 characters will form the CONTAINER ID you see when running docker ps
7. Check it's up and running:
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS b5f42f0a8336 mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 30 seconds ago Up 29 seconds (health: starting) 3306/tcp, 33060-33061/tcp
Connecting to MySQL within the container
1. Rerun the logs command to get the generated password:
$ docker logs mysqli 2>&1 | grep GENERATED GENERATED ROOT PASSWORD: aR8eJVel4fawAj)UmakqEquGexeN
2. Enter this password when first opening mysql:
$ docker exec -it mysqli mysql -uroot -p # enter above passwd
3. Change the password for root user:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
Connecting to container w/out connecting to mysql initially
docker exec -it mysqli bash
This should allow one to start the instance
Disconnecting (and restarting)
docker stop mysqli
And to reconnect:
docker start mysqli # you can also combine this with the above using docker restart mysqli
To delete the mysqli container:
docker rm mysqli