L
L
Leonid2021-12-27 20:05:30
go
Leonid, 2021-12-27 20:05:30

How to do docker build inside Dockerfile?

There is a Dockerfile (important part in bold):

FROM docker:dind
RUN apk add --no-cache go
RUN go version
WORKDIR /app
COPY go.mod ./
ADD index.html /app/index.html
ADD dock /app/dock
ADD flag.txt /app/flag. txt
#COPY go.sum ./
RUN go mod download
COPY *.go ./
RUN go build -o /main
EXPOSE 8080
RUN mv dock Dockerfile
RUN docker build -t interesting_container .
RUN docker run -t -d interesting_container
CMD [ "/main" ]



I want my container to create another container and put a text file there (I'm doing a job for ctf).
When I try to compile this into an image, I get an error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock . Is the docker daemon running?


Googled everything I could, but the only thing I found is that the last CMD command can interfere.
Indeed, without it, you can build the second Dockerfile, but only by hand through docker exec.
What do I need to do so that the second container runs inside the first one and the Go application works (web server)? PS Individually, all these elements (the first container, the second container and the application) work completely as they should without errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drno, 2021-12-27
@Drno

Docker is a container. You can't run a container inside a container...
You have to run 2 containers...
You can run LXC\LXD and have a docker inside... except perhaps

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question