0

I am trying to build an image and then run it in one command. Using stackoverflow question I have menaged to scrape this command:
docker run --rm -it -p 8000:8000 -v "%cd%":/docs $(docker build -q .)

However it produces an error:

docker: invalid reference format.
See 'docker run --help'. 

First part of the command ( docker run --rm -it -p 8000:8000 -v "%cd%":/docs .) works properly on already built image the problem lies inside $(docker build -q .). Dockerfile is inside the folder I have opened in cmd.

MDDawid1
  • 92
  • 11
  • Does this answer your question? [Build and run Dockerfile with one command](https://stackoverflow.com/questions/45141402/build-and-run-dockerfile-with-one-command) – m19v Sep 18 '22 at 18:50
  • @m19v The dupe you linked is already mentioned in the question, so perhaps not... – STerliakov Sep 18 '22 at 18:54
  • Please post your `docker build -q .` sole output. – STerliakov Sep 18 '22 at 18:57
  • Consider using docker-compose. – KamilCuk Sep 18 '22 at 19:20
  • @SUTerliakov `-q` means quiet so it only returns the hash/id of the image: `sha256:14c545392dae8d54e3132f7e16739575ff236a0ebbb56171eed8a5e79574cb57` – MDDawid1 Sep 18 '22 at 19:29
  • @KamilCuk it is for open source project to run the container the easiest way possible so I would rather not use docker-compose. – MDDawid1 Sep 19 '22 at 12:35
  • ( I do not understand. Well, for me, it seems like using an open source tool that is commonly used and is part of docker and simplifies the way of running the container, is the easiest way possible and is a perfect fit for an open source project. ). I cannot reproduce - `echo FROM alpine >> Dockerfile` followed by `docker run -ti --rm "$(docker build -q .)" echo 1` correctly runs the container. Most probably, your `docker build` command is flawed or Dockerfile fails, and you are not seeing the error. – KamilCuk Sep 19 '22 at 12:39
  • I guess ill have to look into docker-compse. Dockerfile is fine and if I use docker build separately it also works. – MDDawid1 Sep 19 '22 at 14:18

1 Answers1

1

You need to run it in PowerShell, not cmd.

Try docker run --rm -it -p 8000:8000 -v ${PWD}:/docs $(docker build -q .).