dockerfile, how to support docker run options -d, -v and -p? - docker

I have a very simple dockerfile:
FROM ubuntu:16.04
ADD node-v6.11.1 /usr/local
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs
RUN node -v
COPY server /server
RUN cd /server && npm install
EXPOSE 80 443
VOLUME ["/server/public"]
CMD cd /server && node server
sudo docker run server works as expected.
sudo docker run server -v /public:/server/public results in:starting container process caused "exec: \"-v\": executable file not found in $PATH".
sudo docker run server -d results in:
starting container process caused "exec: \"-d\": executable file not found in $PATH"
sudo docker run server -p 80:80 gives similar error.

You have to pass the options before the image name as follow:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
For example:
sudo docker run -v /public:/server/public server

Related

Container is exiting on its own & not able to exec into it

I am trying to build and container image & then trying to run the enter the container after running it. But I am getting error response from daemon.
My Docker file -
COPY . /app
RUN sudo chmod 777 -R /app
WORKDIR /app
ADD entry_point.sh /opt/bin/
RUN sudo chmod 777 /opt/bin/entry_point.sh
COPY start-selenium-standalone.sh /opt/bin/start-selenium-standalone.sh
RUN sudo chmod 777 /opt/bin/start-selenium-standalone.sh
EXPOSE 4444 5900 9515
**Command to build docker image**
docker build -f Docker/Dockerfile -t sel-test:1 .
**Command to run the image**
docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm sel-test:1
**Error I am getting -**
Error response from daemon: Container a9e0bb7f381584dd5e39dcd997640233835408ffdfe4e0e44108ddb7bb393cd0 is not running
Your container is exiting because there is nothing to run inside the container.
To see this, run the docker ps -a command and check the status of your container.
In order to run something inside the container use CMD in docker file to run bash inside the container whenever you use 'docker run'.

Difficulty starting Kafka from docker

Docker newb here - I've defined a simple image that grabs and extracts kafka, exposes the port and then tries to start the server.
For some reason it's not seeing the file as executable in the docker container.
My dockerfile is:
FROM openjdk:8u151-jre-alpine
COPY start-kafka.sh /
ENV PATH="${PATH}:/"
RUN chmod a+x start-kafka.sh
RUN wget http://apache.mirror.gtcomm.net/kafka/2.1.0/kafka_2.11-2.1.0.tgz
RUN gzip -d kafka_2.11-2.1.0.tgz
RUN tar -xvf kafka_2.11-2.1.0.tar
RUN ls -la
RUN echo $PATH
EXPOSE 9092
CMD ["start-kafka.sh"]
My start-kafka.sh is:
#!/bin/sh
cd /kafka_2.11-2.1.0
ls
cd bin
ls
cat kafka-server-start.sh
exec "/kafka_2.11-2.1.0/bin/kafka-server-start.sh" "/kafka_2.11-2.1.0/config/server.properties"
When running docker run -p 9092:9092 kafka1 I get the output of the cat command then the following...
/start-kafka.sh: exec: line 8: /kafka_2.11-2.1.0/bin/kafka-server-start.sh: not found
Help please!
Found the answer to this with help from a colleague - the kafka-server-start.sh requires bash, which the alpine image didn't provide. Added the installation of bash to my script and all was good!

Docker Container is not running

Please help. When I want to go into a container is says
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
My DockerFile:
FROM ubuntu:16.04
MAINTAINER Anton Lapitski <a.lapitski#godeltech.com>
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD ./ /usr/src/app
EXPOSE 80
ENTRYPOINT ["/bin/sh", "-c", "/usr/src/app/entry.sh"]
Starting script - start.sh:
sudo docker build -t starter .
sudo docker run -t -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter
entry.sh script:
echo "Hello World"
ls -l
pwd
if mountpoint -q /mounted-directory
then
echo "mounted"
else
echo "not mounted"
fi
sudo docker ps -a gives:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90599013c666 starter "/bin/sh -c /usr/src…" 18 minutes ago Exited (0) 18 minutes ago thirsty_wiles
And mosе important:
sudo docker exec -it 90599013c666 bash
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
Please could you tell what I am doing wrong?
P.S adding -d flag when running not helped.
Once the ENTRYPOINT completes (in any form), the container exits.
Once the container exits, you can't docker exec into it.
If you want to get a shell on the image you just built to poke around in it, you can
sudo docker run --rm -it --entrypoint /bin/sh starter
To make this slightly easier to run, you might change ENTRYPOINT to CMD in your Dockerfile. (Docker will run the ENTRYPOINT passing the CMD as command-line arguments; or if there is no entrypoint just run the CMD.)
...
RUN chmod +x ./app.sh
CMD ["./app.sh"]
Having done that, you can more easily override the command
sudo docker run --rm -it starter /bin/sh
You can try
docker start container_id and then docker exec -ti container_id bash for a stopped container.
You cannot execute the container, because your ENTRYPOINT script has been finished, and the container stopped. Try this:
Remove the ENTRYPOINT from your Dockerfile
Rebuild the image
run it with sudo docker run -it -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter sh
The key is the i flag and the sh at the end of the command.
I tried these two commands and it works:
sudo docker start <container_id>
docker exec -it <containerName> /bin/bash

Unable to run shell in my container [duplicate]

This question already has an answer here:
docker executable file not found in $PATH
(1 answer)
Closed 5 years ago.
I want to dockerize my application and I want to run and enter my container in order to see whether packages were installed properly, files were copied, etc.
Here's my Dockerfile:
FROM node:8.6
RUN mkdir /app
WORKDIR /app
COPY .*.json .
COPY src/ .
USER node
RUN yarn global add #angular/cli
EXPOSE 4200
The problem is, I can't run my container via docker run:
docker run my-notes -it --rm ash
I see errors:
container_linux.go:262: starting container process caused "exec: \"-it\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"-it\": executable file not found in $PATH".
ERRO[0000] error waiting for container: context canceled
What am I doing wrong?
The issue is that you need to pass the docker options before the image name not after that:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
I have answered this question here as well. Hope it helps.
The node image comes with sh, bash and dash.
If you want ash you can install the package, but it's just a symlink to /bin/dash so you can just run:
docker run -it --rm my-notes dash
To install the ash package, add the following to your Dockerfile
RUN set -uex; \
apt-get update; \
apt-get install ash; \
apt-get
Then ash/dash can be run with
docker run -it --rm my-notes ash

docker container volumes from directory access in CMD instruction

docker container volumes from directory access in CMD instruction
$ sudo docker run -d --name ext -v /external busybox /bin/sh
and
run.sh
#!/bin/bash
if [[ -f "/external" ]]
then
echo 'success!'
else
echo 'Sorry, I can't find /external...'
fi
and
Dockerfile
FROM ubuntu:14.04
MAINTAINER newbie
ADD run.sh /run.sh
RUN chmod +x /run.sh
CMD ["bash", "/run.sh"]
and
$ sudo docker build -t app .
and
$ sudo docker run -d --volumes-from ext app
ac57afb95f923eeffd28e7d9d9cb76cb1b7699ebd
So
$ sudo docker logs ac57afb95f923eeffd28e7d9d9cb76cb1b7699ebd
Sorry, I can't find /external...
My question is,
How can I access /external directory in run.sh in CMD instruction
impossible?
Thank you~
modify your run.sh
-f is check for file exists. in this case use -d check for directory exists.
Check if a directory exists in a shell script
futhermore if you want make only volume container, need not add -d, /bin/sh
volume container run command change like this
$ sudo docker run --name ext -v /external busybox

Resources