无法让 Docker 与 headless-wp-starter 一起工作

无法让 Docker 与 headless-wp-starter 一起工作

我在这里发布这个问题,希望我只是错误地使用了 Docker,并且有人可以解释如何修复它。我不认为问题出在无头-WP-启动器GitHub 项目本身,但如果是的话,我会在其他地方询问。

目前,我正在尝试安装它以在 Ubuntu 18.10 上进行本地开发。这是我的安装过程。我确保从上次 Docker 安装中删除卷/图像/容器等,然后从头开始。

  1. 我正在尝试安装 headless-wp-starter,首先安装dockercomposer

    sudo apt install composer docker`
    
  2. 按照 Docker 文档中的说明单独安装 docker-compose这里

  3. 测试 docker-compose 看看一切是否正常。

    docker-compose --version  
    docker-compose version 1.24.0, build 0aa59064  
    
  4. 将 git 的内容移动到位于 的全新文件夹中/opt/lampp/htdocs/headless-wp

    cd /opt/lampp/htdocs/headless-wp  
    sudo docker-compose up -d  
    

    我需要 sudo 因为我得到:

    ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
    
    If it's at a nonstandard location, specify the URL with the DOCKER_HOST environment variable.
    
  5. 一切都很好,直到最后我得到:

    Creating db-headless      ... done
    Creating frontend-graphql ... done
    Creating frontend         ... done
    Creating wp-headless      ... error
    
    ERROR: for wp-headless      
    Cannot start service wp-headless: OCI runtime create failed:   
    container_linux.go:344: starting container process caused "chdir to cwd (\"/var/www/html\") set in config.json failed: 
    permission denied": unknown   
    ERROR: for wp-headless      
    Cannot start service wp-headless: OCI runtime create failed:    
    container_linux.go:344: starting container process caused "chdir to cwd (\"/var/www/html\") set in config.json failed: permission denied": unknown      
    ERROR: Encountered errors while bringing up the project.  
    

我对 Docker 一点都不熟悉。我在 Google 上搜索过这个问题,但还是没能找到解决方案。

通过改变以下部分,我已经能够让 wp-headless 运行 docker-compose.yml

wp-headless:
    build: .
    command: bash -c 'install_wordpress && apache2-foreground'
    container_name: wp-headless
    depends_on:
        - db-headless
    env_file: ./.env
    ports:
        - '8080:8080'
    user: www-data
    volumes:
        - ./wordpress:/var/www/html
        - ./docker/install_wordpress.sh:/usr/local/bin/install_wordpress
        - ./docker/migratedb_import.sh:/usr/local/bin/migratedb_import
        - ./docker/postlightheadlesswpstarter.wordpress.xml:/var/www/postlightheadlesswpstarter.wordpress.xml
        - ./docker/plugins:/var/www/plugins

wp-headless:
    build: .
    command: bash -c 'install_wordpress && apache2-foreground'
    container_name: wp-headless
    depends_on:
        - db-headless
    env_file: ./.env
    ports:
        - '8080:8080'
    user: www-data
    volumes:
        - ./wordpress:/opt/lampp/htdocs/headless-wp
        - ./docker/install_wordpress.sh:/usr/local/bin/install_wordpress
        - ./docker/migratedb_import.sh:/usr/local/bin/migratedb_import
        - ./docker/postlightheadlesswpstarter.wordpress.xml:/var/www/postlightheadlesswpstarter.wordpress.xml
        - ./docker/plugins:/var/www/plugins

即使 WordPress 正在运行,也没有 JSON 输出,因此前端不起作用。

编辑:我尝试按照以下步骤安装 Docker这个帖子。我也尝试提取 git 到/var/www/html但仍然收到相同的错误:

/var/www/html/headless-wp-starter-master$ sudo docker-compose up -d
db-headless is up-to-date
frontend-graphql is up-to-date
frontend is up-to-date
Starting wp-headless ... error

ERROR: for wp-headless    
Cannot start service wp-headless: OCI runtime create failed:  
container_linux.go:345: starting container process caused "chdir to cwd   (\"/var/www/html\") set in config.json failed: permission denied": unknown
ERROR: for wp-headless    
Cannot start service wp-headless: OCI runtime create failed:  
container_linux.go:345: starting container process caused "chdir to cwd (\"/var/www/html\") set in config.json failed: permission denied": unknown  
ERROR: Encountered errors while bringing up the project.

链接至完整安装日志

问题:

  • 这个安装看起来正确吗或者我在某个地方犯了错误?

  • 我是否应该将从 GitHub 下载的 headless-wp-starter 移动到 Docker 预先确定的其他文件夹?

  • 我安装的 Docker 版本正确吗?似乎有很多版本,这也造成了混乱。

答案1

docker和中大多数绑定的语法docker-composehost-item:container-item。因此,当您执行以下操作时:

    volumes:
        - ./wordpress:/opt/lampp/htdocs/headless-wp

您正在将本地绑定./wordpress/opt/lampp/htdocs/headless-wp容器中,但 WP 配置文件中没有任何内容指向它。由于原始配置正在创建绑定相对的主机目录(./wordpress)和容器中的预期目录,您不需要更改这一点。

相关内容