docker-compose.yml file:
web:
build: ./code
ports:
- "80:80"
volumes:
- ./mount:/var/www/html
dockerfile in ./code
:
FROM wordpress
WORKDIR /var/www/html
RUN touch test.txt
This is a production environment I'm using to set up a simple WordPress blog (omitted other services in docker-compose.yml & Dockerfile for simplicity).
Here's what I'm doing:
- Bind mounting host directory at container destination
/var/www/html
- Create
test.txt
file during build time
What's NOT working:
- When I inspect
/www/var/html
on the container, I don't find mytest.txt
file
What I DO understand:
- Bind mounting happens at run-time
- In this particular case file gets created, but the when you mount the host directory, commands in Dockerfile get overridden
- When you use volume mount, It works
What I DON'T understand:
- What are the ways in which you can get your latest code into the container which is using a bind mount to persist data?
- How can one create a script that can let me achieve this in runtime?
- How else can I achieve this considering I HAVE to use a bind mount (AWS ECS persists data only when you use a host directory path for a volume)