Compose: Copying application files/folders into container from host filesystem

Created on 30 Dec 2017  ยท  4Comments  ยท  Source: docker/compose

Hi,

First of all this is more of an advice/help request than an issue. I am facing this issue hence reason I am here.

ubuntu@linux:~/hello-world$ tree -a
.
โ”œโ”€โ”€ config
โ”‚ย ย  โ””โ”€โ”€ params.yml
โ”œโ”€โ”€ docker
โ”‚ย ย  โ”œโ”€โ”€ docker-compose.yml
โ”‚ย ย  โ”œโ”€โ”€ .env
โ”‚ย ย  โ””โ”€โ”€ nginx
โ”‚ย ย      โ””โ”€โ”€ Dockerfile
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ Readme.md
โ””โ”€โ”€ src
    โ””โ”€โ”€ controller
        โ”œโ”€โ”€ default.php
        โ””โ”€โ”€ user.php

5 directories, 9 files

When I create my container(s), I want everything you see above copied into nginx_con container. Obviously Dockerfile below or similar ones won't work. How can I achieve this? What is the best practise?

nginx/Dockerfile

FROM nginx:1.13.8

...
COPY ./../ /usr/share/nginx/html
...

docker-compose.yml

version: '3'

services:
    nginx_img:
        container_name: nginx_con
        build: ./nginx
        ports:
            - 1000:80

Thanks

kinquestion

Most helpful comment

Try

build:
  context: ..
  dockerfile: ./nginx/Dockerfile

All 4 comments

If the structure above is too complex, I am happy to use structure below so content of src folder should be copied into /usr/share/nginx/html when I run docker-compose up.

ubuntu@linux:~/hello-world$ tree -a
.
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ nginx
โ”‚ย ย  โ””โ”€โ”€ Dockerfile
โ””โ”€โ”€ src
    โ”œโ”€โ”€ Readme.md
    โ””โ”€โ”€ config
    โ”œโ”€โ”€ index.php
    โ””โ”€โ”€ ......
2 directories, 4 files

Try

build:
  context: ..
  dockerfile: ./nginx/Dockerfile

Thank you. Work perfectly fine.

I am facing same issue , can you please help

wget someurl | tar zxf - -C ${SP_HOME} && \
rm -rf ${SP_HOME}/config && \
chmod 555 /wrapper.sh
COPY ../newconfig ${SP_HOME}/config

Forbidden path outside the build context: ../newconfig ()
Build step 'Execute shell' marked build as failure

Was this page helpful?
0 / 5 - 0 ratings