1、编辑数据源
不会vim的可以用nano
apt install nano
nano /etc/apt/sources.list
编辑完按ctrl + x 按 y 再按回车 保存完成
vi /etc/apt/sources.list
删除全部内容并修改为
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
2、更新数据源
apt-get update
旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:
apt-get remove docker \
docker-engine \
docker.io
3、使用脚本自动安装或者APT安装
脚本自动安装
-
curl -fsSL get.docker.com -o get-docker.sh
-
sudo sh get-docker.sh --mirror Aliyun
APT安装
- 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common - 安装 GPG 证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - - 写入软件源信息
sudo add-apt-repository “deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable” - 更新并安装 Docker CE
sudo apt-get -y update
sudo apt-get -y install docker-ce
4、启动 Docker CE
sudo systemctl enable docker
sudo systemctl start docker
5、安装docker-compose
apt install docker-compose
6、创建镜像yml配置(不能按tab键)
mkdir /usr/local/docker
cd /usr/local/docker
vi docker-compose.yml
7、tomcat 配置
version: ‘3.1’
services:
tomcat:
restart: always
image: tomcat
container_name: tomcat
ports:
- 8080:8080
volumes:
- /usr/local/docker/tomcat/webapps/test:/usr/local/tomcat/webapps/ROOT
environment:
TZ: Asia/Shanghai
8、MySQL配置
MySQL5
version: ‘3.1’
services:
mysql:
restart: always
image: mysql:5.7.22
container_name: mysql
ports:
- 3306:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command:
–character-set-server=utf8mb4
–collation-server=utf8mb4_general_ci
–explicit_defaults_for_timestamp=true
–lower_case_table_names=1
–max_allowed_packet=128M
–sql-mode=“STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO”
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
8、MySQL8配置
version: ‘3.1’
services:
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
command:
–default-authentication-plugin=mysql_native_password
–character-set-server=utf8mb4
–collation-server=utf8mb4_general_ci
–explicit_defaults_for_timestamp=true
–lower_case_table_names=1
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8080:8080
#Dockerfile的写法(用的jetty)
FROM jetty
WORKDIR /var/lib/jetty/webapps
RUN mkdir ROOT
WORKDIR /var/lib/jetty/webapps/ROOT
COPY my-shop-web-admin-1.0.0-SNAPSHOT.zip /var/lib/jetty/webapps/ROOT
RUN unzip my-shop-web-admin-1.0.0-SNAPSHOT.zip
WORKDIR /var/lib/jetty