Reputation: 10872
My local folder looks like so:
docker-compose.yml
\nginx-proxy
\code
index.html
nginx.conf
Dockerfile
index.html
contains plain html code. nginx.conf
contains this simple configuration:
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
server {
listent 80;
root /code;
index index.html;
}
}
Dockerfile
contains these instructions:
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
COPY ./code /code
And finally docker-compose
contains these instructions:
nginx:
build: ./nginx-proxy
container_name: nginx-proxy
ports:
- "8181:80"
When I run docker-compose up
and go to localhost:8181
for some reason I see a welcoming nginx page (not my index.html), if, however, I slightly change docker-compose.yml:
nginx:
build: ./nginx-proxy
container_name: nginx-proxy
ports:
- "8181:80"
volumes:
- ./nginx-proxy/code:/code
- ./nginx-proxy/nginx.conf:/etc/nginx/nginx.conf
So, my question is why do I have to specify this volumes
instructions? I wish I could instead use my Dockerfile with COPY instructions.
Upvotes: 0
Views: 112
Reputation: 9954
Generally you will not need them, until you for example want to change code on the host and see the changes on the docker container.
Your setup looks good, all you need is defining your build context like
build: context: ./nginx-proxy
Other then that your COPY statements will copy the contents right like you expecting during build time , so there is no need to use volumes during runtime for this ( except the sync case as outlined at the top )
Upvotes: 2