Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从本地目录复制到名为volume的docker中,并将其装载到NGINX容器上?_Docker_Nginx_Docker Compose_Docker Swarm_Docker Volume - Fatal编程技术网

如何从本地目录复制到名为volume的docker中,并将其装载到NGINX容器上?

如何从本地目录复制到名为volume的docker中,并将其装载到NGINX容器上?,docker,nginx,docker-compose,docker-swarm,docker-volume,Docker,Nginx,Docker Compose,Docker Swarm,Docker Volume,我想将public目录复制到一个命名卷中,并将其装载到所有Nginx容器中 这是我的docker-compose.yml: version: '3.7' services: # http://localhost:8187/ nginx: # build: . image: nginx # container_name: nginx ports: - "8187:80" networks: - public volum

我想将
public
目录复制到一个命名卷中,并将其装载到所有Nginx容器中

这是我的docker-compose.yml:

version: '3.7'
services:
  # http://localhost:8187/
  nginx:
    # build: .
    image: nginx
    # container_name: nginx
    ports:
      - "8187:80"
    networks:
      - public
    volumes:
      - nginx_logs:/var/log/nginx/
      - nginx_public:/usr/share/nginx/html

      # invalid mount config for type…
      # - ./public:/usr/share/nginx/html:cached

      # error: invalid mount config for type "bind": bind source path does not exist: /Users/admejiar/Code/uxer-analytics/events-hub/public"
      # - type: bind
      #   source: ./public
      #   target: /usr/share/nginx/html


networks:
  public:

volumes:
  nginx_logs:
  nginx_public:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: $PWD/public

使用此命令(Nginx除外),一切都正常(请参阅全文):

Nginx容器出现故障,原因是:

未能装入本地卷:mount./public:/var/lib/docker/volumes/events-hub\u nginx\u public/\u数据,标志:0x1000:没有这样的文件或目录

如果我检查命名卷,我有以下内容:

$ docker volume inspect events-hub_nginx_public                                                                                                                                                                                                                      v12.3.1
[
    {
        "CreatedAt": "2019-07-27T00:01:56Z",
        "Driver": "local",
        "Labels": {
            "com.docker.stack.namespace": "events-hub"
        },
        "Mountpoint": "/var/lib/docker/volumes/events-hub_nginx_public/_data",
        "Name": "events-hub_nginx_public",
        "Options": {
            "device": "./public",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]

我认为问题在于,将本地目录“public”复制到指定卷的部分没有发生。关于如何解决这个问题,你有什么想法吗?

在问题中加一个。你不能使用像“/public”这样的相对路径,这是问题的一部分。。。
$ docker service ps events-hub_nginx --no-trunc                                                                                                                                                                                                                      v12.3.1
ID                          NAME                     IMAGE                                                                                  NODE                DESIRED STATE       CURRENT STATE             ERROR                                                                                                                                            PORTS
5jdf3m5fgu4elr8ig0blc5wqq   events-hub_nginx.1       nginx:latest@sha256:eb3320e2f9ca409b7c0aa71aea3cf7ce7d018f03a372564dbdb023646958770b   node2               Ready               Rejected 1 second ago     "failed to mount local volume: mount ./public:/var/lib/docker/volumes/events-hub_nginx_public/_data, flags: 0x1000: no such file or directory"
$ docker volume inspect events-hub_nginx_public                                                                                                                                                                                                                      v12.3.1
[
    {
        "CreatedAt": "2019-07-27T00:01:56Z",
        "Driver": "local",
        "Labels": {
            "com.docker.stack.namespace": "events-hub"
        },
        "Mountpoint": "/var/lib/docker/volumes/events-hub_nginx_public/_data",
        "Name": "events-hub_nginx_public",
        "Options": {
            "device": "./public",
            "o": "bind",
            "type": "none"
        },
        "Scope": "local"
    }
]