I've a docker image which is used in my Jenkins Pipeline to do a bunch of stuff such as building and running tests. Those tests uses docker. The image runs perfectly fine on the Jenkins Pipeline. I'm trying to connect to that images locally. I've followed the steps below:
1. docker-compose build
2. docker run -it container_name /bin/bash
After entering the container, I want to run the tests that use docker and getting the error below: connect ENOENT /var/run/docker.sock
Also, I tried running docker ps
I'm getting this: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Any suggestions for this?
Edit 1: my docker-compose.yml looks like:
version: '2.0'
services:
build:
build: .
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
entrypoint: sh
command: >
sh -c "npm install"
Dockerfile:
FROM Imageeee
USER root
WORKDIR /app
COPY ./package*.json ./
RUN npm install
COPY ./ ./
RUN npm run build
docker run
doesn't use the configuration defined in the docker-compose.yml
spec. Not mounting the docker
daemon socket, and without running the docker
daemon inside the container, there is no docker
daemon to connect to.
You can define your service configuration in YAML format:
version: '3.7'
services:
build:
image: docker:20.10.12-dind
container_name: dind
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
... then use docker-compose run...
to create a container
... or update the docker run
command line, eg:
docker run --rm -it \
--entrypoint docker \
-v /var/run/docker.sock:/var/run/docker.sock \
docker:20.10.12-dind ps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.