docker安装

一、使用 apt 存储库安装

  1. 更新软件包索引并安装软件包以允许使用 基于 HTTPS 的存储库:

    1
    2
    sudo apt-get update
    sudo apt-get install ca-certificates curl gnupg
  2. 添加 Docker 的官方 GPG 密钥:

    1
    2
    3
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
  3. 使用以下命令设置存储库:

    1
    2
    3
    4
    echo \
    "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
    "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

二、安装 Docker 引擎

  1. 更新包索引:apt

    1
    sudo apt-get update
  2. 安装 Docker Engine、containerd 和 Docker Compose。

    要安装最新版本,请运行:

    1
    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  3. 通过运行映像验证 Docker 引擎安装是否成功。hello-world

    1
    sudo docker run hello-world

    此命令下载测试映像并在容器中运行它。当 容器运行,它会打印确认消息并退出。

您现在已成功安装并启动 Docker 引擎。

三、安装docker compose

1
2
sudo apt-get update
sudo apt-get install docker-compose-plugin

Docker 疑难

一、exec /entrypoint.sh: no such file or directory

在Windows上使用Dockerfile,加入shell文件时,需要注意该shell文件行尾序列应该保存为LF,而不是CRLF,否则容易发生报错如上报错。

Mysql安装

一、在 Ubuntu 上安装 MySQL

1
2
sudo apt update
sudo apt install mysql-server

一旦安装完成,MySQL 服务将会自动启动。想要验证 MySQL 服务器正在运行,输入:

1
sudo systemctl status mysql

输出应该显示服务已经被启用,并且正在运行:

1
2
3
4
5
6
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-04-28 20:59:52 UTC; 10min ago
Main PID: 8617 (mysqld)
Status: "Server is operational"
...

二、保护加固 MySQL

MySQL 安装文件附带了一个名为mysql_secure_installation的脚本,它允许你很容易地提高数据库服务器的安全性。

不带参数运行这个脚本:

1
sudo mysql_secure_installation

运行过程中可能会报错

1
... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

用这个命令进入mysql

1
sudo mysql

在sql命令行输入以下命令回车,你就可以把密码改成mynewpassword

1
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';

exit回到终端命令行,输入:

1
sudo mysql_secure_installation

输入刚才的密码即可。
出现的问题都选n.

三、创建新的用户 for 远程访问

1
2
3
4
5
6
# ① 适用于 MySQL 8.0之前的版本,可以直接授权
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

# ② 适用于 MySQL 8.0之后的版本,需要先创建一个用户,再进行授权【推荐方式②】
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;

之后需要确定/etc/mysql/mysql.conf.d/mysqld.cnf中的bind-address是否为0.0.0.0

此外还有服务器安全组开放3306端口

Reference

[1] Install Docker Engine on Ubuntu | Docker Documentation

[2] Install the Compose plugin | Docker Documentation