0

I´m trying to build an image based on linuxamazon that runs the docker daemon. The idea is to automatically run this image on amazon ec2 and execute a workflow using the boto3 api.

Here is the Dockerfile:

FROM amazonlinux:2

RUN yum update -y
RUN yum install -y amazon-linux-extras
RUN yum install -y unzip
RUN yum install vim-enhanced sudo -y



## install aws-cli2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
    unzip awscliv2.zip && \
    ./aws/install && \
    rm -rf awscliv2.zip

RUN amazon-linux-extras install docker
RUN service docker start

And here is the output

=> ERROR [9/9] RUN service docker start                                                                         1.0s
------                                                                                                                
 > [9/9] RUN service docker start:                                                                                    
#12 0.718 Redirecting to /bin/systemctl start docker.service
#12 0.719 Failed to get D-Bus connection: Operation not permitted
------
executor failed running [/bin/sh -c service docker start]: exit code: 1
make: *** [Makefile:12: build] Error 1

Any idea or recommendation to run docker inside the linuxamazon image ?

david
  • 805
  • 1
  • 9
  • 21
  • Running a Docker daemon inside a Docker container ("Docker in Docker") is complicated and usually isn't recommended. Do you have a specific reason to want a second Docker daemon? Can you use the official [`docker:dind`](https://hub.docker.com/_/docker) image rather than trying to build your own? – David Maze Jul 15 '22 at 00:06
  • Sorry for the confusion. I would like to use only one deamon. What i´m doing is to open an EC2 instance (using boto3 script) and once the instance is up and running i would like to run a docker image (docker un hello-world). My guess is that i need to connect the default /var/run/docker.sock when building the instance. How can i do that ? – david Jul 15 '22 at 13:19
  • You need to bind-mount the host's Docker socket into the container, `docker run -v /var/run/docker.sock:/var/run/docker.sock`. The linked question has further discussion. – David Maze Jul 15 '22 at 13:30

0 Answers0