How can I write the docker -it option in Dockerfile? - docker

I want create a Dockerfile for CMD line:
docker run --rm -it -v $(pwd):/data -p 8080:80 klokantech/openmaptiles-server
How I do -it in Dockerfile?

You can't control the "interactive" (-i) and "tty" (-t) runtime options from the Dockerfile at build time. You'll need to include that in the documentation for how to use your image.

You can pass a string instead of an array in CMD Dockerfile instruction.
So you can type:
CMD "docker run --rm -it -v $(pwd):/data -p 8080:80 klokantech/openmaptiles-server"
Otherwise "-it" should be an element of CMD array.

Related

Unable to run docker build inside docker run

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.
You need to run it in PowerShell, not cmd.
Try docker run --rm -it -p 8000:8000 -v ${PWD}:/docs $(docker build -q .).

I am not able to load tensorflow/serving in my docker container using windows powershell by using the following command

docker run -it -v C:\Users\HP\Documents\Deep Learning\potato_project:/potato_project -p 8605:8605 --entrypoint /bin/bash tensorflow/serving
It is showing docker:invalid reference format.
enter image description here
Try your path into quotes:
docker run -it -v "C:\Users\HP\Documents\Deep Learning\potato_project:/potato_project" -p 8605:8605 --entrypoint /bin/bash tensorflow/serving
Its seems its due to the space in the path name

Exclude a command in docker

I have the following ENTRYPOINT in my Dockerfile:
ENTRYPOINT["/setup.sh"]
I need to run a container without running setup.sh and run install.sh.
How do I do it?
Just change your docker entrypoint when executing docker run :
docker run -d --rm --entrypoint WHATEVER_COMMAND_YOU_WANT image_name
It will replace your dockerfile' entrypoint.

passing dynamic path in docker run command

I am trying to use this command in docker run
docker run -p 80:80 -v $(pwd)/php-docker/src:/var/www/html/ php-hello-world
but it is not working. Is there any way to use pwd in docker run
yes, you can use PWD, use it as variable $PWD instead subshell $(pwd)
docker run -p 80:80 -v $PWD/php-docker/src:/var/www/html/ php-hello-world

How do I append to PATH environment variable when running a Docker container?

I want to mount a volume and add it to the container's PATH environment variable. I've tried the following and none is working.
docker run -it -v $(PWD):/app -e PATH=$PATH:/app/bin debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='$PATH:/app/bin' debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='$$PATH:/app/bin' debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='\$PATH:/app/bin' debian:jessie bash
How do I append the mounted volume to PATH?
If you you use -e option, the $PATH value is the PATH of the host instead of the container.
You can do it like this:
docker run -it -v $(PWD):/app debian:jessie bash -c 'export PATH=$PATH:/app/bin; bash'
Within the docker command line, you can't get "what will be the value of $PATH at runtime". Thus, you cannot append a PATH to the PATH variable, with docker's -e flag. To achieve what you want to do, you will need to do that in a script that will get executed as the cmd / entrypoint of your container.
You can define a fixed Path for your imported Apps and add the new Path to the Apps into the Environment-Variable "Path"
Let's take your Path "/app". In your Dockerfile add the following Line:
ENV PATH=${PATH}:/app/bin
Build your modified Docker
Now you can access all Apps located under < external Directory >/bin that you mount to "/app" via
-v <external Directory>:/app
You can use a shell script (let's call it run.sh):
#/bin/bash
PATH=$PATH:/app/bin
"$#"
and call it from docker:
docker run -it -v $(PWD):/app debian:jessie /app/run.sh bash

Resources