I'm using https://github.com/sagemathinc/cocalc-docker on Linux. I want to be able to edit my host files from within Cocalc. How do I make a folder that is a symbolic link to my host user's home?
If I understood you correctly you are looking for the -v flag when starting a new container.
So something like: docker run -v path:path -t myimage
You can mount your local dir on to your container using docker Volumes. Here's the doc on that https://docs.docker.com/engine/admin/volumes/volumes/#start-a-container-with-a-volume. Here's an example docker-compose.yml file:
version: "3.1"
services:
php-fpm:
build: docker/php-fpm
container_name: vendorapps-php-fpm
working_dir: /application
volumes:
- /localdirOnHost:/DestpathOnContainer
Related
I have a docker-compose.yml
version: '3.3'
services:
ssh:
environment:
- TZ=Etc/UTC
- DEBIAN_FRONTEND=noninterative
build:
context: './'
dockerfile: Dockerfile
ports:
- '172.17.0.2:22:22'
- '443:443'
- '8025:8025'
volumes:
- srv:/srv:rw
restart: always
volumes:
srv:
After I run docker-compose up --build I can ssh to the docker vm and there are files in /srv. 'docker volume ls' shows 2 volumes, srv and dockersetupsrv. They are both in /var/lib/docker/volumes. They both contain _data directories and show creation time stamps that match the docker image creation times but are otherwise empty. Neither one contains any of the files that are in the docker container's /srv directory. How can I share the docker /srv directory with the host?
you should point out more specific for the mapping directory,
for example:
/srv:/usr/srv:rw
after that, when you add content inside your host machine /srv,it is automatically map into /usr/srv
--> make sure that directory exist
you can have a check in this link : https://docs.docker.com/storage/volumes/
I have a very simple docker-compose.yml file where I use nginx and mounting a file as a volume.
But everytime I run the application, it is creating a directory .htpasswd without really mounting the .htpasswd file where I locally.
This is the docker-compose.yml.
version: '3'
services:
reverse:
container_name: reverse
hostname: reverse
restart: unless-stopped
image: nginx
ports:
- 80:80
- 443:443
volumes:
- ./nginx/.htpasswd:/etc/nginx/conf.d/.htpasswd
Can someone help me fix this?
by default if binded to a none existent path, docker will create a folder, the solution would be in your case to create the path before running your docker-compose
How are you running Docker? here's an answer ...
For Mac with Minikube/Hyperkit docker and Docker Compose
Since I'm not using Docker Desktop any longer, I've experienced numerous issues similar to "docker in docker (dind)" paradigm with minikube...
mount minikube
use absolute path
e.g., easiest way was to mount the exact home path...
minikube mount $HOME:/Users/<you>
... keeps running...
docker-compose.yaml
volumes:
- /Users/<you>/path/to/file.yaml:/somedir/file.yaml
I have the following docker-compose.yml configuration:
version: '3'
services:
proxy:
image: nginx:latest
container_name: webproxy
ports:
- "80:80"
volumes:
- /etc/nginx/sites-available:/etc/nginx/sites-available
On my host machine I have a nginx.conf file at /etc/nginx/sites-available/nginx.conf.
Steps:
Start the container with docker-compose -up
Go into the command line of the container with sudo docker exec -it 687 /bin/bash
cd into /etc/nginx/sites-available
Unfortunately the folder in step 3 is empty. My nginx.conf file is not being copied.
Is my docker-compose file not configured properly, or are volumes not supposed to also copy and start with the host data?
Doesn't looks anything wrong in docker-compose.yaml , because I used the same file as mentioned by you to create docker container. It worked for me. check your content inside /etc/nginx/sites-available on your host machine.
I have a docker image "doc_image" and a docker volume "doc_volume". I want to spin up a container from the image where the volume is mounted into a specific point
If I do this with docker run like this:
docker run -d -p 5000:5000 -v doc_volume:/directory doc_image
then it runs flawlessly (I can see the expected files in /directory in interactive way). However, when I try to spin it up with docker-compose like with a docker-compose.yml like this:
version '3'
services:
my_service:
image: doc_image
volumes:
- doc_volume:/directory
volumes:
doc_volume:
there is nothing in /directory:
FileNotFoundError: [Errno 2] No such file or directory: '/directory/file.txt'
What went wrong here?
Add external property to volumes section:
version '3'
services:
my_service:
image: doc_image
volumes:
- doc_volume:/directory
volumes:
doc_volume:
external: true # << here we go
Your problem is that docker-compose creates another volume unless you explicitly tell him to use external one. External means creates not by means of docker-compose.
I have a few questions about Docker volumes. I have installed Docker and docker-compose on a fresh host running debian stretch. I managed to get a docker-compose file running for a simple nginx/php-fpm project, both containers mounted on the directory containing the source code. I wanted to try to create a single volume that would be shared across my containers but I have a few issue, and my understanding of the official documentation is not helping.
So this is an idea of what I'm trying to achieve :
Question 1 : Trying to create a volume from a dockerfile on a directory mounted from host
docker-compose.yml :
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
php.dockerfile :
FROM php:7-fpm
VOLUME project
from my understanding, when running docker-compose we should have a volume created on host containing all files from /project from container. And /project from container should contain all files from ./host-project-directory from host.
If I ls the content of /project on container I can see the files from host, but using docker volume list, there are no volumes created on host, why ?
Question 2 : How to populate and use this volume from another container ?
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
This should create a volume called 'named-volume' and bind it to /project directories on both containers php and web.
Now, how to populate this volume with content from ./host-project-directory ?
I've tried adding a dockerfile like
ADD ./host-project-directory /project
But nothing changed and the volume remained empty.
I'm sorry if this is due to my lack of experience using Docker but I can't figure out how to make this simple thing work.
Thank you for your time !
For the first question, I try a simple docker file like this:
FROM php:7-fpm
COPY ./project /project
And a docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- named-volume:/project
web:
image: nginx
links:
- php
volumes:
- named-volume:/project
volumes:
named-volume:
Since you create the volume on docker-compose you don't need to create that in the Dockerfile.
Running docker volume list, I'm able to see the volume created with a local driver. Making ls inside the folder I'm also able to see the file. It's important to note, that the file present in you local directory it's not the same that the file inside the container. So if you edit the files in the host this will not change the files in container. That's because you have your volume created in another path, probably at: /var/lib/docker/volumes/...
This happens because you map the volume to the path, but you not specifies where you want the volume. To do that just make your docker-compose like this:
version: '3'
services:
php:
build: .
volumes:
- ./project:/project
web:
image: nginx
links:
- php
volumes:
- ./project:/project
Making this I'm still able to see the volume with the volume list command but without a name.
So I don't know why you are not able to see the volume in the list.
For question 2:
Doing the example above I have the files inside the container that exists in my local "project" folder.
Please check that the path to the local folder is correct.
A bind mount is not the same thing as a volume. You're defining a named volume here, but wanting the functionality of a bind mount.
Try this
version: '3'
services:
php:
build:
context: .
dockerfile: php.dockerfile
volumes:
- ./host-project-directory:/project
web:
image: nginx
links:
- php
volumes:
- ./host-project-directory:/project