欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker 容器编排的应用

程序员文章站 2022-06-03 14:14:08
...

案例一

提前安装好docker-compose
使用 mysql:5.6 镜像和 WordPress:latest镜像,在/root/wordpress目录下创建docker-compose.yaml文件,编排部署WordPress,并设置restart策略

[aaa@qq.com ~]# mkdir wordpress
[aaa@qq.com ~]# cd wordpress/
[aaa@qq.com wordpress]# vi docker-compose.yaml
注意每一行的缩进
mysql:
  image: mysql:5.6  
  restart: always
  ports:
    - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: 123456
    MYSQL_DATABASE: wordpress
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: 123456

wordpress:
  image: wordpress:latest
  restart: always
  ports:
    - "80:80"
  links:
    - "mysql:mysql"
  environment:
    WORDPRESS_DB_NAME: wordpress
    WORDPRESS_DB_USER: wordpress
    WORDPRESS_DB_PASSWORD: 123456

启动测试
[aaa@qq.com wordpress]# docker-compose up -d 
Creating wordpress_mysql_1 ... done
Creating wordpress_wordpress_1 ... done

查看启动是否成功
[aaa@qq.com wordpress]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
f521eb4ab925        wordpress:latest    "docker-entrypoint..."   22 seconds ago      Up 20 seconds       0.0.0.0:80->80/tcp       wordpress_wordpress_1
1ab669a6cb05        mysql:5.6           "docker-entrypoint..."   26 seconds ago      Up 22 seconds       0.0.0.0:3306->3306/tcp   wordpress_mysql_1

浏览器登录访问
Docker 容器编排的应用

案例二

使用 mysql:5.6 镜像和 owncloud :latest镜像,在/root/owncloud目录下创建docker-compose.yaml文件,编排部署owncloud,并设置restart策略

[aaa@qq.com ~]# mkdir owncloud
[aaa@qq.com ~]# cd owncloud/
[aaa@qq.com owncloud]# vi docker-compose.yaml
mysql:
  image: mysql:5.6 
  restart: always
  ports:
    - "3306:3306"
  environment:
    MYSQL_ROOT_PASSWORD: 123456
    MYSQL_DATABASE: owncloud
    MYSQL_USER: owncloud
    MYSQL_PASSWORD: 123456

owncloud:
  image: owncloud:latest 
  restart: always
  ports:
    - "80:80"
  links:
    - "mysql:mysql"
  environment:
    WONCLOUD_DB_NAME: owncloud
    WONCLOUD_DB_USER: owncloud
    WONCLOUD_DB_PASSWORD: 123456

启动测试
[aaa@qq.com owncloud]# docker-compose up -d 
Creating owncloud_mysql_1 ... done
Creating owncloud_owncloud_1 ... done

查看启动状态
[aaa@qq.com owncloud]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
5877ec11c807        owncloud:latest     "docker-entrypoint..."   29 seconds ago      Up 27 seconds       0.0.0.0:80->80/tcp       owncloud_owncloud_1
db8a0d1e7645        mysql:5.6           "docker-entrypoint..."   30 seconds ago      Up 29 seconds       0.0.0.0:3306->3306/tcp   owncloud_mysql_1

浏览器访问测试
Docker 容器编排的应用

相关标签: docker centos