I am trying to run my docker image, but I am receiving the following error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"python3\": executable file not found in $PATH": unknown.
ERRO[0000] error waiting for container: context canceled
Here is my Dockerfile:
FROM python:3.6-alpine3.7
RUN apk add --no-cache python3-dev \
&& pip3 install --upgrade pip
RUN apk add --no-cache --update \
python3 python3-dev gcc \
gfortran musl-dev
RUN apk add --no-cache libressl-dev musl-dev libffi-dev
RUN python3.6 -m pip install --upgrade pip
RUN apk --no-cache add git
RUN apk add mariadb-dev
WORKDIR /socialworks-api
COPY . /socialworks-api
RUN pip3 --no-cache-dir install -r requirements.txt
ENV PATH="/opt/gtk/bin:$env/development.env"
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["app.py"]
I think the issue might be with the ENV PATH which I set. I have also tried setting it to:
ENV PATH="/opt/gtk/bin:${env/development.env}"
But I would receive the following error when building my dockerfile:
Step 11/14 : ENV PATH="/opt/gtk/bin:${env/development.env}"
failed to process "\"/opt/gtk/bin:${env/development.env}\"": missing ':' in substitution
Without setting the environment, my application won't run.
I have also tried running on my dockerfile this command:
RUN export $(grep -v '^#' ./env/development.env | xargs)
It build successfully, but when I enter this command to the terminal:
docker run -it flaskapp
I am receiving an error that it still unable to locate the env variables.
$ docker run -it flaskapp
Traceback (most recent call last):
File "app.py", line 11, in <module>
app.config.from_object("config.Config")
File "/usr/local/lib/python3.6/site-packages/flask/config.py", line 174, in from_object
obj = import_string(obj)
File "/usr/local/lib/python3.6/site-packages/werkzeug/utils.py", line 568, in import_string
__import__(import_name)
File "/socialworks-api/config.py", line 4, in <module>
class Config(object):
File "/socialworks-api/config.py", line 5, in Config
MYSQL_HOST = os.environ['MYSQL_HOST']
File "/usr/local/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'MYSQL_HOST'
In your Dockerfile you specify
ENV PATH="/opt/gtk/bin:$env/development.env"
When you later run python3, the system looks in only these two directories, and when there's not a Python there, you get the error you see. It's probably in /usr/bin/python3, but the directory /usr/bin isn't in $PATH.
The simplest answer here is to delete this line entirely. Your Dockerfile creates neither a /opt/gtk nor a /development.env directory, so there's no files in either path that could be executed. If you do need to install custom software, putting it in a directory that's in the default system path (like /usr/local/bin) is a good approach.
If you do need to keep this line, make sure the existing $PATH stays as part of the value.
ENV PATH="/opt/gtk/bin:$PATH"
(Don't specify ENTRYPOINT ["python"]; combine this into a single CMD ["python3", "app.py"]. I'd encourage you to run docker run --rm -it yourimage /bin/sh to look around the filesystem and run debugging commands like env, but the ENTRYPOINT declaration breaks this use, and having the script file named in the CMD means it's still not the "container-as-command" pattern.)
Related
I want to preface this in saying that I am very new to docker and have just got my feet wet with using it. In my Docker file that I run to build the container I install a program that sets some env variables. Here is my Docker file for context.
FROM python:3.8-slim-buster
COPY . /app
RUN apt-get update
RUN apt-get install wget -y
RUN wget http://static.matrix-vision.com/mvIMPACT_Acquire/2.40.0/install_mvGenTL_Acquire.sh
RUN wget http://static.matrix-vision.com/mvIMPACT_Acquire/2.40.0/mvGenTL_Acquire-x86_64_ABI2-2.40.0.tgz
RUN chmod +x ./install_mvGenTL_Acquire.sh
RUN ./install_mvGenTL_Acquire.sh -u
RUN apt-get install -y python3-opencv
RUN pip3 install USSCameraTools
WORKDIR /app
CMD python3 main.py
After executing the build docker command the program "mvGenTL_Acquire.sh" sets env inside the container. I need these variables to be set when executing the run docker command. But when checking the env variables after running the image it is not set. I know I can pass them in directly but would like to use the ones that are set from the install in the build.
Any help would be greatly appreciated, thanks!
For running a bash script when your container is creating:
make an script.sh file:
#!/bin/bash
your commands here
If you are using an alpine image, you must use #!/bin/sh instead of #!/bin/bash on the first line of your bash file.
Now in your Dockerfile copy your bash file in the container and use the ENTRYPOINT instruction for running this file when the container is creating:
.
.
.
COPY script.sh /
RUN chmod +x /script.sh
.
.
.
ENTRYPOINT ["/script.sh"]
Notice that in the ENTRYPOINT instruction use your bash file address in your image.
Now when you create a container, the script.sh file will be executed.
After some help I succeded to build the image of my Java Application and then able to run it in a container. Now I would like to add ExpressVPN inside the same container and wounder how do I do that? I can see that on DockerHub their is some polkaned/expressvpn with connection to Github to see all the files
Is it possible to just copy the code from the Dockerfile (of polkaned) and add it to my Dockerfile? Then I have understood that I will have to use somekind of script file in my Entrypoint instead where I state the commands and information that needs to get ExpressVPN running.
I have tried but failed. This is how I did:
FROM debian:bullseye-slim
ENV ACTIVATION_CODE Code
ENV LOCATION smart
ENV PREFERRED_PROTOCOL auto
ENV LIGHTWAY_CIPHER auto
ARG APP=expressvpn_3.18.1.0-1_amd64.deb
RUN apt-get update && apt-get install -y --no-install-recommends \
libterm-readkey-perl ca-certificates wget expect iproute2 curl procps libnm0 \
&& rm -rf /var/lib/apt/lists/* \
&& wget -q "https://www.expressvpn.works/clients/linux/${APP}" -O /tmp/${APP} \
&& dpkg -i /tmp/${APP} \
&& rm -rf /tmp/*.deb \
&& apt-get purge -y --auto-remove wget
COPY entrypoint.sh /tmp/entrypoint.sh
COPY expressvpnActivate.sh /tmp/expressvpnActivate.sh
#
# Build stage
#
FROM maven:3.8.4-openjdk-17 AS build
COPY src /test/src
COPY pom.xml /test
#RUN mvn -f /test/pom.xml clean package
RUN mvn -f /test/pom.xml clean package
#
# Package stage
#
FROM openjdk:17-alpine
COPY --from=build /test/target/test-0.0.1-SNAPSHOT.jar /usr/local/lib/test.jar
ENTRYPOINT ["/bin/bash", "/tmp/entrypoint.sh"]
An image is created but when I try to start it I get the following error:
Error invoking remote method 'docker-run-container': Error: (HTTP code 400) unexpected - OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin": permission denied: unknown
I change entrypoint to /bash and got this:
Error invoking remote method 'docker-run-container': Error: (HTTP code 400) unexpected - OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
then I removed /bin/bash and got this:
Error invoking remote method 'docker-start-container': Error: (HTTP code 400) unexpected - OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/tmp/entrypoint.sh": stat /tmp/entrypoint.sh: no such file or directory: unknown
What I really want to complete is that I in the end would like to be able to run "docker run .."
and then ExpressVPN should start and my Java Application should start after ExpressVPN have connected in the same container. Is this possible?
I have been trying to get my application working - but I keep getting an error:
Task Stop Reason: Essential container in task exited; Container myapp Status Reason: CannotStartContainerError: API error (400): OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"docker-compose up\": executable file not found in $PATH": unknown
My Dockerfile:
FROM node:9.10.0
COPY / /myapp
WORKDIR /myapp
RUN chown -R node:node /myapp
USER node
RUN mkdir /home/node/.npm-global
ENV PATH=/home/node/.npm-global/bin:$PATH
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
RUN npm install -g #angular/cli
RUN npm install
USER root
ENV USER root
RUN apt-get update && \
apt-get install -y \
python \
python-dev \
python-pip \
python-setuptools \
&& pip install --upgrade awscli \
&& apt-get clean
Now my task definition (deploy.yaml) is pretty simple and a part of it is:
....
task:
taskRole: "<role>"
containerDefinitions:
- command:
- "docker-compose up"
...
When deploying the app, ECS normally runs docker run I assume, while I need docker-compose up to start my services (in docker-compose.yaml). Where do I run this command, or how do I fix this path?
If you look closer to the error message :
starting container process caused "exec: \"docker-compose up\": executable file not found in $PATH": unknown
You notice that Docker is trying to find an executable named "docker-compose up" in PATH. This is probably incorrect,it should have looked for a "docker-compose" executable (note the missing "[space] up" in exe path).
This is probably caused by a wrong "-command" YML properties.
You should have something like :
...
-command :
-docker-compose
-up
I experienced the same problem with the ENTRYPOINT command in the Dockerfile :
ENTRYPOINT ["command with parameters"]
is invalid. You must have
ENTRYPOINT ["command", "with", "parameters"]
This is the Dockerfile:
FROM lambci/lambda:build-python3.6
# Copy in your requirements file
ADD requirements.txt /requirements.txt
# Copy your application code to the container
RUN mkdir /code/
WORKDIR /code/
ADD . /code/
ENV PS1 'zappa#$(pwd | sed "s#^/var/task/\?##")\$ '
ADD zappa_settings.json /var/task/zappa_settings.json
WORKDIR /var/task
RUN virtualenv /var/venv && \
source /var/venv/bin/activate && \
pip install -U pip zappa && \
pip install -r /requirements.txt && \
deactivate
CMD ["zappa"]
However, when I run docker-compose up I get:
Recreating basesite_web_1 ...
Recreating basesite_web_1 ... error
ERROR: for basesite_web_1 Cannot start service web: oci runtime error: container_linux.go:262: starting container process caused "exec: \"zappa\": executable file not found in $PATH"
ERROR: for web Cannot start service web: oci runtime error: container_linux.go:262: starting container process caused "exec: \"zappa\": executable file not found in $PATH"
ERROR: Encountered errors while bringing up the project.
I assume it's because I need to activate the virtualenv. I want to be able to run the project on my local machine for development. What am I missing? Thanks!
I am using windows 7. In my home folder I made a new directory Docker. And inside that I made new directory rails.
This is my docker file: (Docker/rails/Dockerfile)
FROM alpine:3.2
MAINTAINER xxx <xxx#xxx.in>
ENV BUILD_PACKAGES bash curl-dev ruby-dev build-base
ENV RUBY_PACKAGES ruby ruby-io-console ruby-bundler
# Update and install all of the required packages.
# At the end, remove the apk cache
RUN apk update && \
apk upgrade && \
apk add $BUILD_PACKAGES && \
apk add $RUBY_PACKAGES && \
rm -rf /var/cache/apk/*
RUN mkdir /usr/app
WORKDIR /usr/app
COPY Gemfile /usr/app/
COPY Gemfile.lock /usr/app/
RUN bundle install
COPY . /usr/app
And then I changed directory to Docker. On ls it shows rails.
Then I typed this command:
docker build rails
Now the image name is alpine. I made a tag to rails like this:
docker tag <imageid> myname/rails
Problem:
The image is successfully build and I have a repository rails and pushed it successfully. I am able to pull it as well.
Till now everything is fine, but then I run this command:
docker run -i -t xxx/rails /bin/bash
It gives me this error:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: oci runtime error: exec: "/bin/bash": stat /bin/bash: no such file or directory.
So I am stuck there.
My Objective:
I want to run this command successfully:
rails -v
To run that command I need to install the image, and I don't know how to install the image, I have been following up numerous tutorials since last week.
I am new to docker. This is my first docker image.
Edit:
docker exec -it sh
Alpine does not come with bash by default, only /bin/sh so you should change your command to:
docker run -i -t vikaran/rails sh
Also worth noting you can run:
docker build -t myname/rails rails
To automatically tag the image when building it.