Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker: not found after mounting /var/run/docker.sock

I'm trying to use docker command inside container. i use this command to mount /var/run/docker.sock and run container

docker run -d --name gitlab-runner --restart always \                                                                  
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  gitlab/gitlab-runner:latest

but when i try to use docker inside container(gitlab-runner) i get an error

docker: not found

host:

srw-rw----  1 root docker    0 Mar 23 15:13 docker.sock

container:

0 srw-rw---- 1 root gitlab-runner    0 Mar 23 15:13 docker.sock

this worked fine, before i removed old container and created new one, and now i'm unable to run docker inside container. Please help.

like image 955
David H Avatar asked Dec 03 '22 18:12

David H


1 Answers

You should differentiate between docker daemon and docker CLI. First one is a service, which actually performs all work - builds and runs containers. The second one is an executable, used to send commands to daemon.

Executable (docker CLI) is lightweight and uses /var/run/docker.sock to access daemon (by default, there are different transports actually).

When you start your container with -v /var/run/docker.sock:/var/run/docker.sock you actually share your host's docker daemon to docker CLI in container. Thus, you still need to install docker CLI inside container to make use of Docker, but you dont need to setup daemon inside (which is pretty complicated and requires priviledged mode).

Conclusion

Install docker CLI inside container, share socket and enjoy. But upon using host's docker daemon, you will probably be confused with bind mounting volumes because daemon doesn't see the container's internal file system.

like image 160
grapes Avatar answered Dec 27 '22 05:12

grapes