0

I just started working with docker and am quite enthusiastic so far! At the moment, I am trying to build an extremely basic and extendable file that just serves basic static websites. I figured that this shouldn't be so difficult, but I have the following problem:

The following docker-compose.yml file still shows the default nginx index.html file, I expected that this would be overwritten by my project folder ./code. Can I overwrite all files in /usr/share/nginx/html without adding a separate Dockerfile? I am trying to keep this configuration as minimal as possible.

version: '2'

services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
    volumes:
      - ./code:/usr/share/nginx/html

  // Whenever needed php/python/dababase services can be added here
3
  • I've just tested your compose file as-is and it worked as expected. I created a simple index.html file in a ./code directory. Stop and start your Docker service and see if that resolves it; I've unfortunately had similar problems that a stop and start resolved. Commented Dec 27, 2016 at 16:37
  • Hmm strange, I only see the 'Welcome to nginx!' html file. Also after restarting my service. Commented Dec 27, 2016 at 19:35
  • The only thing I can think of after that would be that your ./code file is not at the same level as your docker-compose.yml file. Try placing a full path instead of the relative ./code and see if that resolves it. Commented Dec 27, 2016 at 19:41

1 Answer 1

2

So I got it working by adding the :z label on my volumes command. So the last line in my code became:

- ./code:/usr/share/nginx/html:z

According to the docker documentation the labels :z and :Z change the label in the container context. These suffixes tell Docker to relabel file objects on the shared volumes. The :z option tells Docker that two containers share the volume content. As a result, Docker labels the content with a shared content label. Shared volume labels allow all containers to read/write content. The :Z option tells Docker to label the content with a private unshared label. Only the current container can use a private volume.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.