0
votes

I try create docker container container with nginx. (Windows 10 64 bit)

  site:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "8080:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

And got error:

ERROR: for site  Cannot start service site: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/e/laravel-docker-new/docker-compose-laravel/nginx
/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/cc15f98e2704e4be5aa3d26ab7a216f3c301ebfcf678c951c2ae5aefad0f794a/merged\\\" at \\\"/var/lib/docker/overlay2/cc15f98e2704e4be5aa3d26ab7a216f3c301ebfcf678c951c2ae5aefad0f794a/merged/etc/nginx/conf.d/default.conf\\
\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

How fix this?

Update.
Try conf

 site:

image: nginx:stable-alpine
container_name: nginx
ports:
  - "8080:80"
volumes:
  - ./src:/var/www/html/public
   ./nginx/default.conf COPY /etc/nginx/conf.d/default.conf
depends_on:
  - php
  - mysql
networks:
  - laravel

But how use artisan?

artisan: build: context: . dockerfile: php.dockerfile container_name: artisan volumes: - ./src:/var/www/html/public depends_on: - mysql working_dir: /var/www/html/public entrypoint: [ '/var/www/html/public/artisan'] networks: - laravel

And how I can got access to laravel?

Files structure

E:/laravel-docker-new/docker-compose-laravel

.github
nginx
nginx/default.conf
src
src/app
src/bootstrap
src/config
src/database
src/public
src/resources
src/routes
src/storage
src/test
src/tests
src/vendor
src/.editorconfig
src/.env
src/.env.example
src/.gitattributes
src/.gitignore
src/.styleci.yml
src/composer.phar
3
Could you please clarify if you are using docker for Mac or windows and where your project folder is located on the host system?Andreas Jägle
I use Windows 10 64 bitpikalivo

3 Answers

0
votes

Do you still encounter the error if you omit this line?

- ./nginx/default.conf:/etc/nginx/conf.d/default.conf

You may be better off using the Docker COPY directive to place that file into the desired location, since if you are trying to use volume mounts as a means to reflect live changes in your code without the need to rebuild the image this will not work as expected for Nginx configuration files, as this would require an Nginx restart to take effect.

0
votes

There is some strange error fallback if the mounted file doesn’t exist on the host. Is there really an nginx folder next to the compose file containing a default.conf? Also, using relative paths doesn’t work in all cases. Please make sure the file really exists on the host system and maybe try passing an absolute path using $pwd (although I’m pretty sure relative paths work with compose - they don’t with plain docker run).

Check this answer for more details: How to mount a single file in a volume

Based on your updated question I assume the problem is caused by your sources being put on the E:\ drive which is not available to the virtual machine running your containers by default. You might need to go to the settings of your docker for windows and add this path to the available shared folders.

For details see: https://docs.docker.com/docker-for-windows/troubleshoot/#volume-mounting-requires-shared-folders-for-linux-containers

0
votes

In my case it was failing to mount the folder because docker expects an absolute path:

$ sudo docker run -v "./nginx.conf:/etc/nginx/nginx.conf" -p 8081:80 -d nginx
docker: Error response from daemon: create ./nginx.conf: "./nginx.conf" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
$ sudo docker run -v /home/ubuntu/nginx/nginx.conf:/etc/nginx/nginx.conf -p 8081:80 -d 
nginx57f95da476a6794a26530b6140066b3362c166c3040eb8d3be0aece916441402