Create an image with a VOLUME (Dockerfile):
# Specifies the base image as Node.js on Alpine Linux, which is a lightweight Linux distribution.
FROM node:alpine
# Sets the working directory inside the container to "/home".
WORKDIR /home
# Copies all files from the current directory (the context) into the "/home" directory of the container.
COPY . .
# Runs the npm install command to install the dependencies of the Node.js application.
RUN npm i
# Exposes port 8000, indicating that the application inside the container will be accessible on this port.
EXPOSE 8000
# This command creates a Docker volume named "images" at the specified path "/home/images" inside the container. Volumes are used to persist data outside of the container filesystem, and they can be shared among multiple containers.
VOLUME ["/home/images"]
# Specifies the default command to run when the container starts, launching the Node.js application using the "app.js" script.
CMD ["node", "app.js"]
Build the image:
docker build -t propscode254/dockervolumes:latest .
docker run -d -p CONTAINER_NEW_PORT:DOCKER_FILE_PORT IMAGEID/NAME
For example
View the new volume in Docker Desktop:
Add an image to this port (7000) with Thunder client. Check Docker Desktop to see the new image inside the volume:
docker run -d -p CONTAINER_NEW_PORT:DOCKER_FILE_PORT -v NAMEOFVOLUME:DOCKERFILE_VOLUME_PATH IMAGEID/NAME
View the new volume with the given name on your desktop:
Use Thunderclient to send an image on the specified port, and you'll get a new image in that volume
docker run -d -p CONTAINER_NEW_PORT:DOCKER_FILE_PORT -v ABSOLUTEPATH:DOCKERFILE_VOLUME_PATH IMAGEID/NAME
For Example:
A new image is added to the images folder (previously only one):
No new volume appears in your Docker Desktop.
USE the same VALUE NAME/PATH of the old CONTAINER wenn you create the new container !
Sehe how many volumes:
docker volume ls
Stop Container:
docker container stop id1 id2 id2
Remove more containers (id1-> id one Container):
docker container rm -f id1 id2 id2
Navigate inside with this command in your container and use ls and cd folder as you normally do. For example to find your images in your Volume home/images
docker exec -it containerId/Name sh
(Remember to me: I deleted all images & containers of this repo)