I want to build a docker image in docker container.
So, I tried to create a docker-installed ubuntu docker image following https://docs.docker.com/engine/installation/linux/ubuntu/, but failed.
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y \
apt-transport-https \
ca-certificates \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
RUN apt-get update && \
apt-get install -y docker-ce
When I run docker images
or other commands on the docker image created by above Dockerfile, the error happens.
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Is there any way to solve this problem? Thanks.
Besides the affect of AWS environment, the problem you have is caused by that you did not start docker daemon inside your container, as the error message shown.
Here's the steps to show how to make it work manually:
Start and enter a container using the image built from your Dockerfile
:
docker run --privileged -it dind /bin/bash
And here is the problem you have:
root@82d6eab69331:/# docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Start docker daemon
inside this container:
root@82d6eab69331:~# /usr/bin/dockerd -H unix:///var/run/docker.sock > dockerd.log 2>&1 &
Check log file to make sure it started correctly, and then try docker images
:
root@82d6eab69331:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
So you may need to add entrypoint
to start docker daemon
in your Dockerfile
. I test on environment of CentOS 7.2
and docker 1.12
. Hope this could be helpful to you :-)
AWS CodeBuild doesn't "[..] allow customers to bring in their own Docker-in-Docker images [..]" yet.
We currently only support Docker-in-Docker (dind) with the official CodeBuild images
Source (Jan 12, 2017):
cannot connect to Docker daemon - you might need to run...
Maybe, you can see the result this command.
$ sudo docker images
You should add your user in docker group.
And then, you can use docker command without 'sudo'.
$ sudo usermod -aG docker ${USER}
$ sudo service docker restart
Next, you have to logout in your OS.
Finally, when you login, you can use docker command without 'sudo'.