Basically I want to run a Container that takes the .c file in my directory, compiles it, runs it and exits the container.
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y gcc
WORKDIR /home/
COPY test.c /home/
RUN gcc start.c
CMD ["./a.out"]
This was my previous Dockerfile and it worked when executing with docker run -it --rm <image name>. The Problem is that when I change the c file I have to build a new image and run it again and that takes ages. My current approach is this:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y gcc
WORKDIR /home
CMD ["gcc start.c"]
CMD ["./a.out"]
I run this with docker run -it --rm -v ~/Desktop/docker_c:/home <image-name> but it throws me this error:
starting container process caused "exec: \"./a.out\": stat ./a.out: no such file or directory": unknown.
The -v flag to mount the shared folder is in the run command, so shouldn't the container mount the folder everytime it gets executed?
Thanks for your help !
Related
AM completely new to Docker, now am trying to create a container for tomact from ubuntu base image & written a docker file acoding to it:
From ubuntu
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install wget -y
RUN apt-get install openjdk-8-jdk -y
RUN mkdir /usr/local/tomcat
RUN wget https://mirrors.estointernet.in/apache/tomcat/tomcat-8/v8.5.61/bin/apache-tomcat-8.5.61.tar.gz
RUN tar xvzf apache-tomcat-8.5.61.tar.gz
RUN mv apache-tomcat-8.5.61 /usr/local/tomcat/
#MD ./usr/local/tomcat/apache-tomcat-8.5.61/bin/catlina.sh run
EXPOSE 8080
RUN /usr/local/tomcat/apache-tomcat-8.5.61/bin/catlina.sh run
Created Docker image for the respective docker file using:
docker build -t [filename] .
Tried to start the container using: docker run -itd --name my-con -p 8080:8080
but the container is not starting & the container is listed in stopped container
Cn any one help me fixing this issue
Thanks.
try this in last line:
CMD ["/usr/local/tomcat/bin/catalina.sh","run"]
I'm trying to use the docker image of a specific software (picard), and that image is designed to be run interactively, in fact, an already built docker image is provided via Dockerhub:
docker pull broadinstitute/picard
This image works perfectly will the following command:
sudo docker run -i -t -v $PWD:/usr/working broadinstitute/picard
So that within the image one could launch the actual program like:
java -jar /usr/picard/picard.jar [COMMAND] [OPTIONS] ...
What I am trying to accomplish is to execute this image without entering in an interactive shell, simply as:
sudo docker run --rm -v $PWD:/usr/working broadinstitute/picard [COMMAND] [OPTIONS] ...
As far as I understand, this could be done by creating an ENTRYPOINT in the Dockerfile (see it in appendix below), but addind the following line at the bottom of the Dockerfile will not work:
ENTRYPOINT ["java -jar /usr/picard/picard.jar"]
Instead, when I run the image as above, no output is generated, and if a specific command is called (e.g. CreateSequenceDictionary), I get the following error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"CreateSequenceDictionary\": executable file not found in $PATH": unknown.
What am I missing?
Dockerfile
The dockerfile can be found in the github repo at: https://github.com/broadinstitute/picard/blob/master/Dockerfile. It looks like the following:
FROM openjdk:8
MAINTAINER Broad Institute DSDE <dsde-engineering#broadinstitute.org>
ARG build_command=shadowJar
ARG jar_name=picard.jar
# Install ant, git for building
RUN apt-get update && \
apt-get --no-install-recommends install -y --force-yes \
git \
r-base \
ant && \
apt-get clean autoclean && \
apt-get autoremove -y
# Assumes Dockerfile lives in root of the git repo. Pull source files into container
COPY / /usr/picard/
WORKDIR /usr/picard
# Build the distribution jar, clean up everything else
RUN ./gradlew ${build_command} && \
mv build/libs/${jar_name} picard.jar && \
./gradlew clean && \
rm -rf src && \
rm -rf gradle && \
rm -rf .git && \
rm gradlew && \
rm build.gradle
RUN mkdir /usr/working
WORKDIR /usr/working
The problem is how the ENTRYPOINT is defined.
It should be
ENTRYPOINT ["java", "-jar", "/usr/picard/picard.jar"]
src: https://docs.docker.com/v17.09/engine/reference/builder/#entrypoint
I just learnt about other possible alternative that does not require to modify the original dockerfile, which is overriding the default ENTRYPOINT from the CLI (even if the original image does not define one).
This can be done with the --entrypoint option, but it will only take the name of the file to be executed within the image. If additional arguments are to be used, these must be called after the image name. For example:
docker run --entrypoint="java" $PWD:/usr/working broadinstitute/picard -jar /usr/picard/picard.jar [COMMAND] [OPTIONS]
This blog explains a bit more on the topic.
I am not able to build my Dockerfile without the following error:
/bin/sh: 1: apt-get update : not found
I am able to start a container using the docker run command, with no problems and can run apt-get update using docker run --rm -it ubuntu:16.04 bash
My Dockerfile:
FROM ubuntu:16.04
# Install Packages
RUN apt-get update
Building using:
docker build -t demo/app .
You should pass apt-get update as an argument to bash in docker run command.
docker run --rm -it ubuntu:16.04 bash -c "apt-get update"
To work with this
FROM ubuntu:16.04
# Install Packages
RUN apt-get update
You need to build it first, then tag it and run it.
docker build -t demo/app .
After build you do not need to update for now
docker run --rm -it demo/app bash
I have a dockerfile look like this
FROM ubuntu
MAINTAINER abc <abc.yur#gmail.com>
RUN apt-get update
RUN apt-get install nano
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get -y install golang-go git
RUN mkdir /work
ENV GOPATH=/work
RUN go get github.com/abc/golang
RUN go build github.com/abc/golang
CMD /golang -addr $ADDR -workers $WORKERS
So I want to build and run container but after the building (docker build .) I can not run this container. So when I am running docker ps -a or docker ps there is not container to run
docker build .
This creates the image and not a container. You need to use
docker images
To get the list of images.
docker ps will show when you run a container using something like below
docker run -d <image>
If I run my Dockerfile with the following command, the docker container starts running and all is well.
docker run --name test1 -i -t 660c93c32a
However, if I run this command without the -it, the container does not appear to be running as docker ps returns nothing:
docker run -d --name test1 660c93c32a
.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
All I'm trying to do is run the container and then be able to attach and/or open a shell in the container later.
Not sure if the issue is in my dockerfile or not, so have pasted the dockerfile below.
############################################################
# Dockerfile to build Ubuntu/Ansible/Django
############################################################
# Set the base image to Ansible
FROM ubuntu:16.10
# File Author / Maintainer
MAINTAINER David
# Install Ansible and Related Deps #
RUN apt-get -y update && \
apt-get install -y python-yaml python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools python-pkg-resources git python-pip
RUN mkdir /etc/ansible/
RUN echo '[local]\nlocalhost\n' > /etc/ansible/hosts
RUN mkdir /opt/ansible/
RUN git clone http://github.com/ansible/ansible.git /opt/ansible/ansible
WORKDIR /opt/ansible/ansible
RUN git submodule update --init
ENV PATH /opt/ansible/ansible/bin:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
ENV PYTHONPATH /opt/ansible/ansible/lib
ENV ANSIBLE_LIBRARY /opt/ansible/ansible/library
# Update the repository sources list
RUN apt-get update -y
RUN apt-get install python -y
RUN apt-get install python-dev -y
RUN apt-get install python-setuptools -y
RUN apt-get install python-pip
RUN mkdir /ansible/
WORKDIR /ansible
COPY ./ansible ./
WORKDIR /
RUN ansible-playbook -c local ansible/playbooks/installdjango.yml
ENV PROJECTNAME davidswebsite
CMD django-admin startproject $PROJECTNAME
When you run your container, command after CMD or ENTRYPOINT becomes $1 process of you container. If this process doesn't run well, your container will die.
So, check container logs using: docker logs <container id>
and recheck your command in CMD django-admin startproject $PROJECTNAME