0

I need to have an ubuntu image and then run a build process using that image. All is well until the build gets to the point of doing docker build etc.

Lets say I use the following to test this:

Dockerfile

FROM ubuntu:latest

I then build that - docker build -t ubuntudkr . Next, I run it like:

docker run -ti -v /var/run/docker.sock:/var/run/docker.sock ubuntudkr

When I then run docker ps inside this container, I get the error bash: docker: command not found

All the examples I've found says I need to run:

docker run -v /var/run/docker.sock:/var/run/docker.sock \
           -ti docker

They all use the docker image which contains the docker library. Is my answer then to install docker inside my base image to make it work? Does this then not go against what docker themselves says?

There are many other blog posts out there that gave the same advice, but my example does work. Where do I go wrong?

mieliespoor
  • 945
  • 2
  • 8
  • 23
  • In general, a Docker image should be self-contained; if your application needs a `docker` binary then your Dockerfile needs to install it in some form. (But also remember that being able to access the Docker socket means you can pretty trivially root the entire host; do you _need_ to launch more containers from inside a container, or can you use a safer approach?) – David Maze Aug 03 '21 at 20:57
  • 1
    other containers won't be launched, no. This is for a CI build environment, so only need to run docker build and docker run publish commands will be run. – mieliespoor Aug 03 '21 at 21:23

1 Answers1

0

Replace the image ubuntu:latest in your dockerfile by the official docker:latest image wich contains docker binaries and does exactly what you want: https://hub.docker.com/_/docker

If you want to keep the Ubuntu image, you must install Docker tools following your error. By default, the Ubuntu image does not contain Docker binaries as a regular Ubuntu installation.

Xavier Brassoud
  • 697
  • 6
  • 14