My issue is related to Docker compose to wait Kibana till Elasticsearch stayed up. After that Kibana will start, below codes written for this issue. But it is created an error:
**Step 6/6 : RUN chmod +x entrypoint.sh
---> Running in 2e2d9c229ced
standard_init_linux.go:207: exec user process caused "exec format error"
ERROR: Service 'kibana' failed to build: The command '/bin/sh -c chmod +x entrypoint.sh' returned a non-zero code**
Dockerfile in Kibana:
FROM docker.elastic.co/kibana/kibana:6.6.2
COPY ./config/kibana.yml /opt/kibana/config/kibana.yml
COPY entrypoint.sh entrypoint.sh
USER root
ENTRYPOINT ["sh", "/entrypoint.sh"]
RUN chmod +x entrypoint.sh
entrypoint.sh: in kibana
# Wait for the Elasticsearch container to be ready before starting Kibana.
echo "Stalling for Elasticsearch"
while true; do
nc -q 1 elasticsearch 9200 2>/dev/null && break
done
echo "Starting Kibana"
/usr/local/bin/kibana-docker
Related
I am using a private docker hub repository https://hub.docker.com/u/privaterepoexample/, after which I have built my docker image using the commands below:
docker login
docker build -t privaterepoexample/sre:local .
docker tag 85cf9475bc1c privaterepoexample/sre
docker push privaterepoexample/sre
The output of docker build which shows login.sh added to container:
Executing busybox-1.29.3-r10.trigger
OK: 85 MiB in 57 packages
Removing intermediate container 12fd67450dfc
---> e9ca0b9e4ac4
Step 5/7 : WORKDIR /opt
---> Running in ce881ede94aa
Removing intermediate container ce881ede94aa
---> 2335b4f522ac
Step 6/7 : ADD login.sh /opt
---> 2aabf1712153
Step 7/7 : CMD ["chmod 755 login.sh && ./login.sh"]
---> Running in 8ec824d4e561
Removing intermediate container 8ec824d4e561
---> c97a4ad61578
Successfully built c97a4ad61578
Successfully tagged privaterepoexample/sre:local
The Dockerfile below is built successfully and login.sh is added successfully:
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
curl
FROM openjdk:8-jre-alpine
RUN apk --no-cache add curl
WORKDIR /opt
ADD login.sh /opt
CMD ["chmod 755 login.sh && ./login.sh"]
Now here comes with my problem, when I execute docker run like below, I get the error:
docker run -i privaterepoexample/sre
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"chmod 755 login.sh && ./login.sh\": stat chmod 755 login.sh && ./login.sh:
no such file or directory": unknown.
but why does it say no such file? given when I go inside the docker container, I can see the login.sh script with the command below:
$ docker run -it
privaterepoexample/sre /bin/sh
/opt # ls
login.sh
/opt # cat login.sh
#!/bin/sh
# Black Box Tester!
content=$(curl --location --request POST
"https://api.platform.abc.com/auth/oauth/token" --header
'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic ' --data-raw 'grant_type=password&
username=event#abc.com&password=fJff'| jq -r
'.domain_id' )
if [ $content = abc ]
then
echo “Valid Login Token”
else
echo “invalid url”
fi
/opt # exit
You get the error no such file or directory because you are using a so-called CMD in exec form in an unexpected way.
You can fix your Dockerfile in several ways, e.g.:
either use a CMD in shell form:
CMD chmod 755 login.sh && ./login.sh
or keep a CMD in exec form (which is often a good idea), but ensure the first argument of the JSON array is a program, not a composite command. You can do this e.g. by running chmod 755 … beforehand, at build time:
ADD login.sh /opt
RUN chmod 755 login.sh
CMD ["./login.sh"]
For more information on the CMD command and its brother command ENTRYPOINT, see also this other SO answer: CMD doesn't run after ENTRYPOINT in Dockerfile
I have the following docker-compose.yml file:
version: "3" services:\ local_db:
build:
context: mssql-data
dockerfile: Dockerfile
ports:
- "1433:1433"
volumes:
- ~/Documents/rfg/temp
environment:
SA_PASSWORD: "D0ckerDev"
ACCEPT_EULA: "Y"
When I run docker-compose up I get the following error:
local_db_1 | /scripts/entrypoint.sh: line 5: /scripts/seed-data.sh: Permission denied
docker_local_db_1 exited with code 126
Where entry point is:
#start SQL Server in the background
/opt/mssql/bin/sqlservr &
# start the seed data script
/scripts/seed-data.sh
Where seed-data.sh was:
sleep 15s cd /scripts
if [ -f /var/opt/mssql/data/initialized ]; then
sleep infinity
fi sleep 15s /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -i setup.sql
touch /var/opt/mssql/data/initialized sleep infinity
and entrypoint.sh:
#start SQL Server in the background
/opt/mssql/bin/sqlservr &
# start the seed data script
/scripts/seed-data.sh
and the Dockerfile:
FROM microsoft/mssql-server-linux:2017-latest
COPY . /scripts
CMD chmod 755 /scripts/*
CMD chmod 755 /scripts/seed-data.sh
CMD /bin/bash /scripts/entrypoint.sh
The above works fine in Windows but on MacOS I get th epermission denied error above..
It looks like you haven't set the correct permissions on your seed-data.sh script. You could just call it like this:
sh /scripts/seed-data.sh
Or you can make sure all your scripts are executable first:
chmod 755 /scripts/*
/scripts/seed-data.sh
I am trying to deploy a nodejs app inside docker container on a prod machine using jenkins.
I have this shell :
ssh -tt vagrant#10.2.3.129<<EOF
cd ~/app/backend
git pull
cat <<EOM >./Dockerfile
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
EOM
docker build -t vagrant/node-web-app .
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker run -p 3000:3000 -d vagrant/node-web-app
exit
EOF
this will connect via ssh to prod machine and create a Dockerfile then build and run image. but it failed.
and this a part of the jenkins logs:
Successfully built 8e5796ea9846
vagrant#ubuntu-xenial:~$ docker kill
"docker kill" requires at least 1 argument.
See 'docker kill --help'.
Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
Kill one or more running containers
vagrant#ubuntu-xenial:~$ docker rm
"docker rm" requires at least 1 argument.
See 'docker rm --help'.
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
vagrant#ubuntu-xenial:~$ docker run -p 3000:3000 -d vagrant/node-web-app
0cc8b5b67f70065ace03e744500b5b66c79941b4cb36d53a3186845445435bb5
docker: Error response from daemon: driver failed programming external connectivity on endpoint stupefied_margulis (d0e4cdd5642c288a31537e1bb8feb7dde2d19c0f83fe5d8fdb003dcba13f53a0): Bind for 0.0.0.0:3000 failed: port is already allocated.
vagrant#ubuntu-xenial:~$ exit
logout
Connection to 10.2.1.129 closed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
It seems like jenkins dont execute the " $(docker ps -q) "
and " $(docker ps -a -q) "
so docker kill and docker rm got 0 arguments.
But why this happen ?
I found the issue,
Just I have to replace "$" with "\$" .
this solve the problem.
My task is to create Dockerfile such that it works the following way:
docker build -t test .
Returns Image named test successfully created
docker run --rm test
Returns Hello world!
docker run --rm test Universe
Returns Hello Universe!
What I have so far:
Dockerfile
FROM ubuntu:14.04
LABEL maintainer="trthhrtz"
CMD if [ $# -eq 0 ]; then echo "Hello world!"; else echo "Hello " + $# + "!"; fi
It does not work in case of input arguments, the error is:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"Universe\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled
It would be easier to:
define an entrypoint script entrypoint.sh with your command logic scripted in it.
COPY that file in your Dockerfile
leave CMD undefined
That way, any additional parameter to your docker run -it --rm myImage arg1 arg2 ... command will be passed to the bash entrypoint.sh script, which will interpret $# correctly, as illustrated in "What does set -e and exec "$#" do for docker entrypoint scripts?".
See "Passing arguments from CMD in docker" for more.
Make sure you have a correct order of arguments when you do docker command.
For example:
docker run --name test-ubuntu -it d37f4165b5d2 bash
instead of
docker run --name test-ubuntu d37f4165b5d2 -it bash
So i've written a Dockerfile for a project, i've defined a CMD to run on starting the container to bootstrap the application.
The Dockerfile looks like
# create our mount folders and volumes
ENV MOUNTED_VOLUME_DIR=sites
RUN mkdir /$MOUNTED_VOLUME_DIR
ENV PATH=$MOUNTED_VOLUME_DIR/sbin:$MOUNTED_VOLUME_DIR/common/bin:$PATH
RUN chown -Rf www-data:www-data /$MOUNTED_VOLUME_DIR
# Mount folders
VOLUME ["/$MOUNTED_VOLUME_DIR/"]
# Expose Ports
EXPOSE 443
# add our environment variables to the server
ADD ./env /env
# Add entry point script
ADD ./start.sh /usr/bin/startContainer
RUN chmod 755 /usr/bin/startContainer
# define entrypoint command
CMD ["/bin/bash", "/usr/bin/startContainer"]
The start.sh script, does some git stuff like cloning the right repo, setting environment vars, as well as starting supervisor.
The start script begins with this
#!/bin/bash
now=$(date +"%T")
echo "Container Start Time : $now" >> /tmp/start.txt
/usr/bin/supervisord -n -c /etc/supervisord.conf
I start my new container like this
docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash
when i login to the container i see that supervisor hasn't been started, and neither has nginx or php5-fpm. the /tmp/start.txt file with a timestamp set from the startContainer script doesn't exist, showing its never ran the CMD in the Dockerfile.
Any hints on to get this fixed would be great
This:
docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID /bin/bash
Says 'run /bin/bash' after instantiating the container. E.g. skip CMD.
Try this:
docker run -d -p expoPort:contPort -t -i -v /$MOUNTED_VOLUME_DIR/$PROJECT:/$MOUNTED_VOLUME_DIR $CONTAINER_ID