Home > Enterprise >  What is the difference between these two docker volumes?
What is the difference between these two docker volumes?

Time:07-20

What is the difference between these two volumes in docker? Will they mount same directory or a directory above? I am so confused.

Also, Why is it when I run a container with latest tag and without latest tag, they show different content. Attaching screenshots for more clarity. Any help or hint is appreciated.

version: '2'

services:

  jenkins:
    volumes:
       - jenkins_data:/var/jenkins_home
    networks:
      - jenkinsnet
    build: ./
    ports:
      - '8080:8080'
      - '50000:50000'

networks:
  jenkinsnet:
    driver: bridge

volumes:
  jenkins_data:

and docker-compose.yml with ./ before jenkins_data

version: '2'

services:

  jenkins:
    volumes:
       - ./jenkins_data:/var/jenkins_home
    networks:
      - jenkinsnet
    build: ./
    ports:
      - '8080:8080'
      - '50000:50000'

networks:
  jenkinsnet:
    driver: bridge

volumes:
  jenkins_data:

Dockerfile

FROM jenkins/jenkins:lts
WORKDIR /var/jenkins_home/
USER root

RUN apt-get update && \
      apt-get update -y
RUN apt-get install wget && apt-get install sudo
RUN sudo apt install software-properties-common -y
RUN sudo apt update -y
# smartcheck jre download

RUN sudo wget https://github.com/gouravthakur39/smartcheck-jre-solidity-scan/blob/main/smartcheck-2.1-SNAPSHOT-jar-with-dependencies.jar
RUN touch abcd
#Update the username and password
ENV JENKINS_USER oodles
ENV JENKINS_PASS oodles

#id_rsa.pub file will be saved at /root/.ssh/
RUN ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''

# allows to skip Jenkins setup wizard
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false

# Jenkins runs all grovy files from init.groovy.d dir
# use this for creating default admin user
COPY default-user.groovy /usr/share/jenkins/ref/init.groovy.d/

VOLUME /var/jenkins_home

enter image description here

enter image description here

enter image description here

enter image description here

CodePudding user response:

When using jenkins_data, you're using a named volume which refer to the volume declared at the end of the compose file in volumes section, and the corresponding folder will be created in /var/lib/docker/volumes.

When using ./jenkins_data you're using an host path volume which refer to the the folder jenkins_data next to your compose file.

See https://docs.docker.com/compose/compose-file/compose-file-v3/#volumes

  • Related