What are the permissions set to Jenkins docker container you are using in the instance?
This is one of the solution.
You can use the following docker-compose along with the Dockerfile.
docker-compose.yml
version: "3.7"
services:
jenkins:
build:
context: .
dockerfile: Dockerfile
image: jenkins
container_name: jenkins
restart: always
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/etc/sysconfig/docker:/etc/sysconfig/docker"
- "/home/ubuntu/jenkins/volume:/var/jenkins_home"
ports:
- "8443:8080"
privileged: true
Dockerfile
FROM jenkins/jenkins:lts
#Switching to root user
USER root
RUN apt update && \
apt install sudo curl jq apt-utils -y
RUN curl -sSL https://get.docker.com/ | sh
RUN sudo apt-get install docker-compose -y
#install aws
RUN sudo apt-get install -y python-pip python-dev build-essential
RUN pip install awscli --upgrade --user
RUN export PATH=~/.local/bin:$PATH
#updating path to support aws
ENV PATH="~/.local/bin:${PATH}"
#php installation
#----------------
RUN apt install ca-certificates apt-transport-https
RUN wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
RUN echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
RUN apt update
RUN apt install -y php7.2
RUN apt-get install -y php7.2-common php7.2-opcache php7.2-curl php7.2-mbstring php7.2-mysql php7.2-zip php7.2-xml
#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
#install phpunit
RUN curl -sSL https://phar.phpunit.de/phpunit.phar -o phpunit.phar
RUN chmod +x phpunit.phar
RUN mv phpunit.phar /usr/local/bin/phpunit
Create a volume in the same directory named volume
This will allow you to run the docker command without any issue.