'Dockerfile doesn't write files to host only to container
What I want is for this dockerfile to clone into the host machine (mine) and I'll copy it over as a volume, but instead it's cloning it directly into the container instead.
This is the dockerfile:
FROM php:7.4-apache
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y
RUN a2enmod ssl && a2enmod rewrite
RUN a2enmod include
# Install software
RUN apt-get install -y git
WORKDIR /
RUN git clone mygitrepo.git /test
I also have a different dockerfile that used to write to host, but doesn't anymore:
FROM nginx:1.19.1-alpine
RUN apk update && \
apk add --no-cache openssl && \
openssl req -x509 -nodes -days 365 \
-subj "/C=CA/ST=QC/O=Company Inc/CN=example.com" \
-newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt;
I'm not sure where the root of the problem is. here's the docker-compose file that I use to start this:
version: '3.7'
services:
build:
build:
context: .
dockerfile: build.Dockerfile
networks:
- web
apache:
container_name: Apache
build:
context: ./apache
dockerfile: apache.Dockerfile
ports:
- '127.0.0.1:80:80'
- '127.0.0.1:443:443'
networks:
- web
networks:
web:
volumes:
dump:
I removed a lot of extra stuff so it may appear it doesn't start at all. The containers run fine. The servers run fine. I just want it to write to host and not just the container which is what it's doing. I'm having difficulty googling this. I'm running a macos.
Thank you in advance! :D
Solution 1:[1]
You need to use volumes mapping to be able to do this. Edit your docker-compose file:
volumes:
-${PWD}/:/[container_dir]/
Once this volume mapping is done changes on the host machine is automatically written to the docker container. So, there is no need to think how you can write back from container to the host machine as this fits the purpose well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chiranjeevi Kandel |