AlekseyDanchin
AlekseyDanchin

Reputation: 310

Run docker inside ubuntu container

2 days I try to run the docker inside an ubuntu container:

  1. docker run -it ubuntu bash
  2. Install docker by instruction of https://docs.docker.com/engine/install/ubuntu/ or/and https://phoenixnap.com/kb/how-to-install-docker-on-ubuntu-18-04
  3. Finally I have installed docker:
root@e65411d2b70a:/# docker -v
Docker version 19.03.6, build 369ce74a3c
  1. But when I try to run docker run hello-world have some problem
root@5ac21097b6f6:/# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

In service list not docker:

root@5ac21097b6f6:/# service docker start
docker: unrecognized service
root@5ac21097b6f6:/# service  --status-all
 [ - ]  apparmor
 [ + ]  cgroupfs-mount
 [ - ]  dbus
 [ ? ]  hwclock.sh
 [ - ]  procps
 [ ? ]  ubuntu-fan

When try to run dockerd:

root@5ac21097b6f6:/# dockerd    
INFO[2020-04-23T07:01:11.622627006Z] Starting up                                  
INFO[2020-04-23T07:01:11.624389266Z] libcontainerd: started new containerd process  pid=154
INFO[2020-04-23T07:01:11.624460438Z] parsed scheme: "unix"                         module=grpc
INFO[2020-04-23T07:01:11.624477203Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-04-23T07:01:11.624532871Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-04-23T07:01:11.624560679Z] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2020-04-23T07:01:11.664827037Z] starting containerd                           revision= version="1.3.3-0ubuntu1~18.04.2"
ERRO[2020-04-23T07:01:11.664943052Z] failed to change OOM score to -500            error="write /proc/154/oom_score_adj: permission denied"
...
INFO[2020-04-23T07:01:11.816951247Z] stopping event stream following graceful shutdown  error="context canceled" module=libcontainerd namespace=plugins.moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.1: can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
 (exit status 3)

Not understand why Permission denied if user root.

Install sudo and add root to the group, but it's not help.

apt-get install sudo
usermod -a -G sudo root

- sudo dockerd have the save problem.

How to make work docker inside ubuntu container? Do you have ideas?

ps. I know about docker-in-docker, I need exactly docker inside ubuntu-container

pss. I know about -v /var/run/docker.sock:/var/run/docker.sock - but needed independent the docker service inside ubuntu-container.

Upvotes: 9

Views: 6827

Answers (2)

DannyB
DannyB

Reputation: 14776

When running docker in docker, the container must use the docker engine on your host.

Here is a simple working setup:

1) Create a dockerfile with docker CLI installed. I am using the official compose image, so you also have docker-compose

FROM docker/compose:1.25.5
WORKDIR /app
ENTRYPOINT ["/bin/sh"]

2) When running it, mount the docker sock

$ docker build -t dind .
$ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock dind

Form within the container, you now have docker. Try running docker ps

Upvotes: 7

vkozyrev
vkozyrev

Reputation: 1978

If you want to do docker in docker without -v /var/run/docker.sock:/var/run/docker.sock then I am afraid that there is no good way to do this. Sharing the docker socket from host is the classic way to make docker containers run within another docker container.

Upvotes: 2

Related Questions