Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Thursday, August 16, 2018

Using Docker to Install MySQL server

Using Docker to Install MySQL server
  1. Go to docker official site, download docker file and install in the local machine.

  2. Start docker, type in the following command to ensure docker is running.

    docker images

  3. Download MySQL image form docker hub with following commands.

    docker pull mysql/mysql-server

    docker pull mysql/mysql-server:5.7 (version 5.7)

  4. Start MySQL server in the container, forward the port out for host connection.

    docker run --name mysqld -e MYSQL_ROOT_PASSWORD=1234 -d -p 3306:3306 mysql/mysql-server

    or

    docker run --name mysql57 -e MYSQL_ROOT_PASSWORD=1234 -d -p 3306:3306 mysql/mysql-server:5.7

    -e: Set environment variables

  5. Host connects to MySQL server in docker.

    docker exec -it mysqld bash

    bash> mysql -u root -p (ask for password)

    Using sequel pro , a free GUI to manipulate MySQL server. MySQL Workbench is another good choice!

  6. Stop the container.

    docker stop mysqld

  7. Start the container.

    docker start mysqld

  8. List port mappings or a specific mapping for the container

    docker port mysqld

  9. Remove container.

    docker rm mysqld

  10. Local host client can not connect to the MySQL server since ‘root’ is limited to localhost connection (within the container).

mysql> select host, user from mysql.user;  
+-----------+---------------+  
| host      |      user     |  
+-----------+---------------+  
| localhost | healthchecker |  
| localhost | mysql.session |  
| localhost | mysql.sys     |  
| localhost | root          |  
+-----------+---------------+  
4 rows in set (0.00 sec)

Change root’s access right for all machines.

mysql> update mysql.user set host='%' where user='root';

mysql> select host, user from mysql.user;  
+-----------+---------------+  
|   host    |     user      |  
+-----------+---------------+  
|    %      |     root      |  
| localhost | healthchecker |  
| localhost | mysql.session |  
| localhost | mysql.sys     |  
+-----------+---------------+  
4 rows in set (0.00 sec)

Restart docker afterward.

docker restart mysql57

Thursday, March 23, 2017

Docker Command Note

Docker Command Note
  • Version
    $ docker --version
    Docker version 1.12.0, build 8eab29e

    $ docker-compose --version
    docker-compose version 1.8.0, build f3628c7

    $ docker-machine --version
    docker-machine version 0.8.0, build b85aac1

  • docker pull ubuntu:14.04 download latest ubuntu image

  • docker images list all images

  • docker run

    • deamon mode :
      docker run -d -p 80:80 [ubuntu(image name)] --name webserver nginx
      -d : Run container in background and print container ID
      -p : Publish a container’s port(s) to the host
      80: out/ 80: in
      –name : Assign a name to the container
      nginx : IMAGE

    • interactive mode :
      docker run -it ubuntu:14.04 | bash
      (啟動一台 ubuntu instance,並且切入bash模式)
      -i: interactive mode, 讓操作者擁有互動模式
      -t: terminal, 讓操作者可以使用終端機操作 instance

  • docker ps show containers just running
    docker ps -a show all containers (default shows just running)

  • docker start start one or more stopped containers

  • docker stop stop one or more running containers

  • docker kill kill one or more running containers

  • docker rm remove one or more containers

  • docker rmi remove one or more images

  • docker port xxxx list port mappings or a specific mapping for the running container

Ubuntu Commands

  • sudo apt-get update
  • sudo apt-get dist-upgrade