v2ex_com
校友
校友
  • UID186
  • 粉丝1
  • 关注7
  • 发帖数46
  • 社区居民
  • 忠实会员
阅读:346回复:0

老司机学Docker之初级实战篇-利用Docker-Machine在虚拟主机中使用compose启动Nginx负载均衡实例、设置IP转发在windows中访问

楼主#
更多 发布于:2019-06-20 04:40
这里我将容器 mynginx 的对外映射端口由9090改为80了

docker-compose.yml 如下

networks:
  mynginx-net:
    driver: bridge
    ipam:
     config:
      - subnet: 192.158.0.0/16
services:
  nginx:
    container_name: mynginx
    image: "nginx"
    networks:
      mynginx-net:
        ipv4_address: "192.158.0.4"
    ports:
      - "80:80"
    privileged: true
    volumes:
      - "/home/docker/nginx/nginx.conf:/etc/nginx/nginx.conf"
  web1:
    container_name: web1
    image: "web"
    networks:
      mynginx-net:
        ipv4_address: "192.158.0.3"
    ports:
      - "8080:80"
    privileged: true
    volumes:
      - "/home/docker/nginx/web1/:/var/www/html/"
  web2:
    container_name: web2
    image: "web"
    networks:
      mynginx-net:
        ipv4_address: "192.158.0.2"
    ports:
      - "8081:80"
    privileged: true
    volumes:
      - "/home/docker/nginx/web2/:/var/www/html/"
version: "3"


运行


$ docker-compose up -d
Creating web1 ...
Creating web2    ... error
Creating web1    ... error

ERROR: for web2  Cannot start service web2: cgroups: cannot find cgroup mount destination: unknown

Creating mynginx ... error

ERROR: for mynginx  Cannot start service nginx: cgroups: cannot find cgroup mount destination: unknown

ERROR: for web2  Cannot start service web2: cgroups: cannot find cgroup mount destination: unknown

ERROR: for web1  Cannot start service web1: cgroups: cannot find cgroup mount destination: unknown

ERROR: for nginx  Cannot start service nginx: cgroups: cannot find cgroup mount destination: unknown
ERROR: Encountered errors while bringing up the project.

解决方法 使用docker-machine ssh v1 进入虚拟机,执行如下命令:

sudo mkdir /sys/fs/cgroup/systemd
sudo mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd

再执行


$ docker-compose up -d
就可以正常启动容器了

参考文章:https://blog.csdn.net/ren7wei/article/details/80855779
游客

返回顶部