Difference between revisions of "Docker"

From Bitnami MediaWiki
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Most of this can be found on the [https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html#docker-starting-mysql-server MySQL website]
 +
 
1. Install docker from repos
 
1. Install docker from repos
 
  $ sudo apt-get install docker-ce docker-ce-cli containerd.io
 
  $ sudo apt-get install docker-ce docker-ce-cli containerd.io
Line 53: Line 55:
  
 
6. Now that we have it, we can start it:
 
6. Now that we have it, we can start it:
−
  docker run --name=mysqli --restart on-failure -d mysql/mysql-server:8.0
+
  docker run --name=mysql1 --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 <code>docker ps</code>
 
This generates a 64-character string; its first 12 characters will form the CONTAINER ID you see when running <code>docker ps</code>
  
Line 63: Line 65:
 
===Connecting to MySQL within the container===
 
===Connecting to MySQL within the container===
 
1. Rerun the logs command to get the generated password:  
 
1. Rerun the logs command to get the generated password:  
−
  $ docker logs mysqli 2>&1 | grep GENERATED
+
  $ docker logs mysql1 2>&1 | grep GENERATED
 
  GENERATED ROOT PASSWORD:  aR8eJVel4fawAj)UmakqEquGexeN
 
  GENERATED ROOT PASSWORD:  aR8eJVel4fawAj)UmakqEquGexeN
  
 
2. Enter this password when first opening mysql:
 
2. Enter this password when first opening mysql:
−
  $ docker exec -it mysqli mysql -uroot -p  # enter above passwd
+
  $ docker exec -it mysql1 mysql -uroot -p  # enter above passwd
  
 
3. Change the password for root user:
 
3. Change the password for root user:
Line 73: Line 75:
  
 
===Connecting to container w/out connecting to mysql initially===
 
===Connecting to container w/out connecting to mysql initially===
−
  docker exec -it mysqli bash
+
  docker exec -it mysql1 bash
 
This should allow one to start the instance
 
This should allow one to start the instance
 +
===Disconnecting (and restarting)===
 +
docker stop mysql1
 +
And to reconnect:
 +
docker start mysql1  # you can also combine this with the above using docker restart mysql1
 +
To delete the <code>mysql1</code> container:
 +
docker rm mysql1
 +
There's additional info on upgrades at [https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-getting-started.html#docker-download-image dev.mysql.com] and some more [https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html advanced uses here].

Latest revision as of 18:16, 5 February 2021

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=mysql1 --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[edit]

1. Rerun the logs command to get the generated password:

$ docker logs mysql1 2>&1 | grep GENERATED
GENERATED ROOT PASSWORD:  aR8eJVel4fawAj)UmakqEquGexeN

2. Enter this password when first opening mysql:

$ docker exec -it mysql1 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[edit]

docker exec -it mysql1 bash

This should allow one to start the instance

Disconnecting (and restarting)[edit]

docker stop mysql1 

And to reconnect:

docker start mysql1  # you can also combine this with the above using docker restart mysql1

To delete the mysql1 container:

docker rm mysql1

There's additional info on upgrades at dev.mysql.com and some more advanced uses here.