I want to make sure I understand correctly docker: when i build an image from the current directory running
docker build -t imgfile .
What happens when i change the content of a file in the directory after the image is built? From what i've tried it seems it changes the content of the docker image also dynamically. I thought the docker image was like a zip file that could only be changed with docker commands or logging into the image and running commands.
The dockerfile is :
FROM lambci/lambda:build-python3.8
WORKDIR /var/task
EXPOSE 8000
RUN echo 'export PS1="\[\e[36m\]zappashell>\[\e[m\] "' >> /root/.bashrc
CMD ["bash"]
And the docker run command is :
docker run -ti -p 8000:8000 -e AWS_PROFILE=zappa -v "$(pwd):/var/task" -v ~/.aws/:/root/.aws --rm zappa-docker-image
Thank you
Best,
CodePudding user response:
Your docker run
command isn't really running your image at all. The docker run -v $(pwd):/var/task
syntax overwrites what was in /var/task
in the image with a bind mount to the current directory on the host. So when you edit a file on your host, the container has the same host directory (and not the content from the image) and you see the changes inside the container as well.
You're right that the image is immutable. The image you show doesn't really contain anything, beyond a .bashrc
file that won't usually be used. You can try running the image without the -v
options to see:
docker run --rm zappa-docker-image ls -al
# just shows `.` and `..` directories
I'd recommend making sure you COPY
your application into the image, setting its CMD
to actually run the application, and removing the -v
option that overwrites its main directory. If your goal is to run host code against host files with host supporting data like your AWS credentials, you're not really getting much benefit from introducing Docker in between your application and every single file it uses.