everyone.
Making my first steps with Docker and want to build an NGINX server, where all the configuration files, logs, and web data will be placed on volumes.
Here is my docker-compose.yml.
I expected that all the configuration files from the /etc/nginx, including conf.d file, will be copied to my NGINX volume.
I also created WWW/html/ directory with a custom index.html to replace the standard welcome page.
version: '3.7'
services:
nginx:
image: nginx
ports:
- "80:80"
volumes:
# nginx configs
- ./nginx:/etc/nginx
# projects folder
- ./WWW:/var/www
# nginx logs
- ./nginx-logs:/var/log/nginx
restart: always
But somehow this does not work. Where I was work?
When you mount a directory you override (technically hide, you can still access the real folder in the container) the mount destination with your source. It won't fill your dirs. If you want to extract the contents of those directories, temporarely disable the mounts and use command docker cp. More info in the docs
Related
I'm tring to bind container's content to host folder, so that i can easy edit it, but for some reason it doesn't work!
here my docker-compose file:
version: "3"
services:
webserver:
image: nginx:mainline-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
volumes:
- ./config:/etc/nginx/conf.d
Please note that this is my folder structure before the docker-compose command:
-project
--docker-compose.yaml
Thank you in advance
Mounting a folder from the container on the host is not possible.
To achieve what you want consider the following
First launch the container without any volumes defined
Run docker cp webserver:/etc/nginx/conf.d/. ./config to copy the content of /etc/nginx/conf.d/ to your config folder on the host
Kill the container and relaunch it with the config folder mounted on /etc/nginx/conf.d (like in your original example). This will shadow the nginx config in the container with the one on your local machine
When editing the local files it will reflect in the container.
If you want to persist your changes in the image after you are done, create a new Docker image by building the following Dockerfile
FROM nginx:mainline-alpine
COPY ./config/* /etc/nginx/conf.d/
This is docker compose file looks like
version: '3.3'
services:
portal:
ports:
- '8080:8080'
- '8000:8000'
environment:
- 'revcycle.portal.logger.root=C:/tomcat/logs/'
volumes:
- /src/main/webapp/sampleFiles:/usr/local/tomcat/webapps/portal/sampleFiles:rw
container_name: portal
image: 'portal:latest'
docker-compose up is creating container successfully by when i check the content of the tomcat webapp All the other sibling folder of the sampleFiles are deleted.
Am i missing something with the volumn commands
Same happen when I use Intellji Idea docker plugin Bind mounts in Configuration
It should be like this:
volumes:
- /src/main/webapp/sampleFiles:/usr/local/tomcat/webapps/portal/sampleFiles
as far as i know rw is for cases when you use drivers stuff...
and make sure that /src/main/webapp/sampleFiles is the host folder which have what you need in docker container. Because essentially it will be mapped into docker container. and will replace target folder.
this way siblings for /usr/local/tomcat/webapps/portal/sampleFiles should stay intact. If no, try starting without volumes part and verify that you see siblings.
don't forget to do docker-compose down and docker-compose up -d when you change anything in docker-compose.yaml file
How can I access from the host system files placed during image build inside a docker container?
We build our docker images through the Gitlab CI/CG pipeline. During the build files like 404 pages, etc are placed in a folder at '/app/public/'. On our production server nginx is running on the host system and need to access this file.
When using the docker bind mount to mount a folder from the host system /srv/web/public/:/app/public into the container the content inside the folder /app/public is not accessible anymore.
At the moment we copy this hidden files via ansible to /srv/web/public/ but this is such an ugly workaround.
version: '2'
services:
web:
image: registry.gitlab.com/project_web/web/master:latest
container_name: web
command: bundle exec rails s
entrypoint: /web/rails-entrypoint.sh
volumes:
- /srv/web/public/:/web/public
- /srv/web/log/:/web/log
env_file: .env
ports:
- '127.0.0.1:3333:3000'
We are using docker volume to store some static files from the docker host's folder. When I restart the container the files which are updated/added in the host directory I can see the changes in docker volume.
However, when I delete a file from host machine. The file is not getting deleted. I have to use docker volume as this is a shareable resource.
Following is my docker compose file
version: '2'
volumes:
test-volume: {}
services:
test:
image: test-volume:test1
volumes:
- test-volume:/var/myapp
test-gateway:
image: test-gateway:latest
ports:
- "8080:80"
volumes_from:
- test
volumes:
- ./test-gateway/conf.d:/etc/nginx/conf.d
environment:
- SITE_ROOT=root
- SITE_ROOT_ROUTE_FROM=/
- SITE_ROOT_ROUTE_DIRECTORY=/var/myapp/static
So, if I remove any file from myapp and restart the docker container the file is not getting deleted from the docker volume.
Is there anything I am missing?
In you compose file you are creating a named volumes test-volume. This volume is references in the test and test-gateway services.
This volume has nothing to do with folders on your docker host. Therefore you cannot delete files on the host and expect this will be reflected in your named volume.
In case you want to map a folder on your docker host your need to use the syntax you used for mapping conf.d file.
volumes:
- ./some_folder_on_host:/some_folder_in_container
I do a Symfony project with Docker. In development, I mount my source folder in Nginx and PHP-FPM containers. But for the production, I want to put the code in the PHP-FPM container to do an app container, and share the code with the Nginx container.
In my Dockerfile, I use a VOLUME /var/www/html, but how can I permit the nginx container to access this volume (in docker-compose file) ?
Before the v3, I know there was a volumes_from, but not anymore.
I want place the code inside the container like say here (https://docs.docker.com/compose/production/)
Removing any volume bindings for application code, so that code stays inside the container and can’t be changed from outside
Thanks a lot for your help
Finally, it appear we can use a named volume to do it, remove the VOLUME from the Dockerfile, then just define a name volume, and it takes the value of the first container.
version: '3'
services:
nginx:
build: ./docker/nginx
volumes:
- app_data:/var/www/html:ro
depends_on:
- app
app:
build: ./
volumes:
- app_data:/var/www/html:rw
networks:
- default
volumes:
app_data:
driver: local