Linux快速搭建docker和docker-compose

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、使用脚本自动安装

curl -fsSL get.docker.com -o get-docker.sh

sudo sh get-docker.sh --mirror Aliyun

4、启动 Docker CE
sudo systemctl enable docker

sudo systemctl start docker

5、安装docker-compose

apt install docker-compose

6、创建镜像yml配置(.yml文件不能按tab键)

mkdir /usr/local/docker

cd /usr/local/docker

vi docker-compose.yml

在docker-compose.yml所在目录下:
运行:docker-compose.yml up -d
停止:docker-compose.yml down
7、tomcat 配置
version: ‘2.0’
services:
tomcat:
restart: always
image: tomcat
container_name: tomcat
ports:
- 8080:8080
volumes:
- /usr/local/docker/tomcat/webapps/test:/usr/local/tomcat/webapps/test
environment:
TZ: Asia/Shanghai

8、MySQL配置
MySQL5
version: ‘2.0’
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:

MySQL8
version: ‘2.0’
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

你可能感兴趣的:(docker,linux,微服务)