In this example, we are going to copy application files and folders into container. This is a common practise for production environment to prevent application file access from outside.


Structure


ubuntu@linux:~/symfony$ tree -a
.
├── docker
│   ├── docker-compose.yml
│   └── nginx
│   └── Dockerfile
├── index.html
└── src
├── src-1.html
└── src-2.html

3 directories, 5 files

Files


index.html


ubuntu@linux:~/symfony$ cat index.html
Hello!

src/src-1.html


ubuntu@linux:~/symfony$ cat src/src-1.html
SRC 1

src/src-2.html


ubuntu@linux:~/symfony$ cat src/src-2.html
SRC 2

docker/docker-compose.yml


ubuntu@linux:~/symfony$ cat docker/docker-compose.yml
version: '3'

services:
nginx_img:
container_name: nginx_con
build:
context: ..
dockerfile: ./docker/nginx/Dockerfile
ports:
- 1000:80

docker/nginx/Dockerfile


ubuntu@linux:~/symfony$ cat docker/nginx/Dockerfile
FROM nginx:1.13.8

WORKDIR /usr/share/nginx/html

COPY . .

Build


ubuntu@linux:~/symfony/docker$ docker-compose up -d

Test


ubuntu@linux:~$ curl localhost:1000
Hello!

ubuntu@linux:~$ curl localhost:1000/src/src-1.html
SRC 1

ubuntu@linux:~$ curl localhost:1000/src/src-2.html
SRC 2

ubuntu@linux:~$ docker exec -it nginx_con ls -l
-rw-r--r-- 1 root root 537 Dec 26 2017 50x.html
drwxrwxr-x 3 root root 4096 Dec 25 09:40 docker
-rw-rw-r-- 1 root root 7 Dec 25 09:39 index.html
drwxrwxr-x 2 root root 4096 Dec 25 09:39 src

ubuntu@linux:~$ docker exec -it nginx_con ls -l src
-rw-rw-r-- 1 root root 6 Dec 25 09:39 src-1.html
-rw-rw-r-- 1 root root 6 Dec 25 09:39 src-2.html

ubuntu@linux:~$ docker exec -it nginx_con ls -l docker
-rw-rw-r-- 1 root root 199 Dec 25 09:34 docker-compose.yml
drwxrwxr-x 2 root root 4096 Dec 25 09:40 nginx

ubuntu@linux:~$ docker exec -it nginx_con ls -l docker/nginx
-rw-rw-r-- 1 root root 59 Dec 25 09:40 Dockerfile