We can achieve this by attaching a volume to our Jenkins file from our host file. I will mount docker runtime into our EC2 instance as a volume.

Steps

Step 1: Shut down the running container

Screenshot 2026-07-31 223825.png

Step 2: We will create a new container and we will take on our mounted volume tat is on the server into the new container.

Command: docker run -p 8080:8080 -p 50000:50000 -d \ -v jenkins_home:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:lts

Screenshot 2026-07-31 224820.png

Step 3: Go into the container as a root user and

docker exec -u 0 -it <container id> bash

Screenshot 2026-07-31 225945.png

Step 4: Once inside the docker container, we this curl command, Jenkins container ill get the latest version of docker so that it can run inside the container and then set the correct permissions on the file so that we can run commands using the Jenkins user.

curl [<https://get.docker.com/>](<https://get.docker.com/>) > dockerinstall && chmod 777 dockerinstall && ./dockerinstall

Note: docker.sock file is a Unix socket file used by docker daemon to communicate with the docker client.

Screenshot 2026-07-31 230036.png

Step 5: Add read and Write permission to the docker.sock file

Screenshot 2026-07-31 231307.png

Step 6: Try running a docker command as a Jenkins user

Screenshot 2026-07-31 231434.png