Allows to copy file into and from the container. Example use: docker cp dummy/. silly_ellis:/test - if /test directory doesn't exist it will be created. Dot (.) in the command in a path means all files in a given directory.
Run container in -d (detached mode), with -p on port 3000, --rm (remove container once stopped), --name (name it feedback-app) and attach the volume /app/feedback that should be mapped to feedback with -v flag, lastly create it from tag (feedback-node:volumes). This command allow you to persist the data, even after container was removed and re-created.
Use bind mounts to map local folder on your machine to container app. In this way you can update code on your machine without re-creating the existing container. (shortcut for the full path: -v $(pwd):/app)
Add anonymous volume -v /app/node_modules to container to make sure the the node module folder doesn't get overwritten by our bind mounts folder content.
docker run -v /app/data ...
Creates annonymous volume that is attached to single container, survives container shutdown/restart, unless --rm flag is used. Cannot be shared across containers and be re-used. Volume can be added to the Dockerfile.
docker run -v data:/app/data ...
Creates named volume - cannot be added to the Dockerfile. Created in general - not tied to any specific container. Thanks to that it survices shutdown/restart - removal via Docker CLI. Can be shared accross containers and re-used for same container (across restarts).
docker run -v /path/to/code/:app/code ...
Creates Bind Mount. Location on host file system, not tied to any specific container. It survices container shutdown/restart - removal on host fs. Can be shared across containers and re-used for same container (across restarts).
Adding :ro at the end of container internal path - which overwrites default which is read-write to read-only. This ensures that docker will not be able to write into our folder or subfolders (only user on its host machine can do).
docker volume inspect [volume_name]
Check extra info about the volume, examle usage: docker volume inspect feedback
Example Dockerfile using Volumes
COPY package.json .
RUN npm install
COPY . .
VOLUME [ "/app/feedback" ]
CMD [ "node", "server.js" ]
ARG and ENV Variables
ARG - available inside of the Dockerfile, not accessible in CMD or any application code, example usage: docker build --build-arg
ENV - available inside of the Dockerfile and in application code, set via Dockerfile or --env or -eon docker run command, for example:
Containers can read and write data, but written data is lost if the container is removed.
Volumes are folders on the host machine hdd, managed by Docker, which are mounted into the container (made available, mapped). Can help with data storage. Volumes persist if container shuts down/restarts. A container can weite data into a volume and read data from it. We have:
- Named Volumes - survuve container removal and can be used to store persistent data
- Anonymous Volumes are attached to a container - they can be used to save (temporary) data inside the container
Bind Mounts - folders on the host machine which are specified by the user and mounted into containers like Named Volumes (but we know the path on the host machine). Can help with direct container interaction.
Build ARGuments and Runtime ENVironment variables - can be used to make images and containers more dynamic/configurable