0

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

PepperAddict
  • 888
  • 2
  • 10
  • 16
  • 1
    Do you mean to share data between the docker container and the host machine that it runs on? https://www.digitalocean.com/community/tutorials/how-to-share-data-between-the-docker-container-and-the-host , https://www.section.io/engineering-education/how-to-share-data-between-a-docker-container-and-the-host-computer/ – CloudBalancing Sep 17 '21 at 16:20
  • hi @CloudBalancing thank you! Well yes definitely want to share docker container with the host machine, but I'm trying to set this up with the dockerfile or docker-compose file that way the rest of the my team doesn't have to follow a series of steps to get going. I'll look at this article further. Thank you! – PepperAddict Sep 17 '21 at 16:46
  • 1
    Anything that gets `RUN` in a Dockerfile will only affect the filesystem in the resulting Docker image; a Dockerfile never has any effect on the host filesystem. – David Maze Sep 17 '21 at 17:18
  • 1
    Does this answer your question? [How do I mount a host directory as a volume in docker compose](https://stackoverflow.com/questions/40905761/how-do-i-mount-a-host-directory-as-a-volume-in-docker-compose) – CloudBalancing Sep 17 '21 at 18:30

1 Answers1

0

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.