Can't clone github public repository into Dockerfile's Run order - docker

Premise · What I want to realize
I'm trying to clone a git public Repository into Dockerfiles Run order, but I'm not going well...
testing environment
MacOS Mojave
10.14.6
Docker
19.03.8
python
3.6.10
bash
3.2.57
What I did
**1. make a Dockerfile **
FROM python:3.6
LABEL maintainer="aaa"
SHELL ["/bin/bash", "-c"]
WORKDIR /usr/local/src/
RUN git clone https://path/to/target_repository.git \
&& chmod -R 755 ./target_repository \
&& cd ./target_repository \
&& pip install -r requirements.txt \
&& mkdir -p ./data/hojin/zip \
&& mv ../13_tokyo_all_20200529.zip ./data/hojin/zip/ \
&& sh scripts/download.sh \
&& pip install IPython seqeval \
&& sh scripts/generate_alias.sh \
&& python tools/dataset_converter.py \
&& python tools/dataset_preprocess.py
EXPOSE 80
CMD ["/sbin/init"]
Problems occurring · Error messages
...
Cloning into 'target-repository'...
chmod: cannot access './target-repository': No such file or directory
...
that's all
I got the errors. What shoud I do?
Could you lend me a hand?

I changed a bit your Dockerfile to test with my repo and it works well.
FROM python:3.6
LABEL maintainer="aaa"
SHELL ["/bin/bash", "-c"]
WORKDIR /usr/local/src/
RUN git clone https://path/to/my_repository.git
RUN chmod -R 755 ./my_repository
RUN cd ./my_repository
You can use RUN commands like me to be more clear and make sure that you type exactly the name of folder.

Related

Docker image build failure - wget

I have a docker file in which I do wget to copy something in the image. But the build is failing giving 'wget command not found'. WHen i googled I found suggestions to install wget like below
RUN apt update && apt upgrade
RUN apt install wget
Docker File:
FROM openjdk:17
LABEL maintainer="app"
ARG uname
ARG pwd
RUN useradd -ms /bin/bash -u 1000 user1
COPY . /app
WORKDIR /app
RUN ./gradlew build -PmavenUsername=$uname -PmavenPassword=$pwd
ARG YOURKIT_VERSION=2021.11
ARG POLARIS_YK_DIR=YourKit-JavaProfiler-2019.8
RUN wget https://www.yourkit.com/download/docker/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip --no-check-certificate -P /tmp/ && \
unzip /tmp/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip -d /usr/local && \
mv /usr/local/YourKit-JavaProfiler-${YOURKIT_VERSION} /usr/local/$POLARIS_YK_DIR && \
rm /tmp/YourKit-JavaProfiler-${YOURKIT_VERSION}-docker.zip
EXPOSE 10001
EXPOSE 8080
EXPOSE 5005
USER 1000
ENTRYPOINT ["sh", "/docker_entrypoint.sh"]
On doing this I am getting error app-get not found. Can some one suggest any solution.
The openjdk image you use is based on Oracle Linux which uses microdnf rather than apt as it's package manager.
To install wget (and unzip which you also need), you can add this to your Dockerfile:
RUN microdnf update \
&& microdnf install --nodocs wget unzip \
&& microdnf clean all \
&& rm -rf /var/cache/yum
The commands clean up the package cache after installing, to keep the image size as small as possible.

Why does the build in this dockerfile fail, while exact the same commands run manually succeed?

I'm trying to build the following Dockerfile:
FROM ubuntu:focal
RUN ln -snf /usr/share/zoneinfo/Europe/Berlin /etc/localtime && echo Europe/Berlin > /etc/timezone \
&& apt-get update \
&& apt-get install -y git default-jdk-headless ant libcommons-lang3-java libbcprov-java \
&& git clone https://gitlab.com/pdftk-java/pdftk.git \
&& cd pdftk \
&& mkdir lib \
&& ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar \
&& ant jar
CMD ["java", "-jar", "/pdftk/build/jar/pdftk.jar"]
When building the image, it fails upon the ant step with several errors like this:
[javac] symbol: class ASN1Sequence
[javac] location: class PdfPKCS7
[javac] /pdftk/java/pdftk/com/lowagie/text/pdf/PdfPKCS7.java:282: error: cannot find symbol
[javac] BigInteger serialNumber = ((ASN1Integer)issuerAndSerialNumber.getObjectAt(1)).getValue();
However when starting a container manually (docker run -it --rm ubuntu:focal) and executing exact the same commands (Sure no typo, Copy/Pasted the whole block several times), the build succeeds.
Any idea what might be different during the docker build and a manually started container?
Wow, this one is a tricky one. 🔎
When you build the container, the program which executes your instruction set is shell (/bin/sh) whereas when you run docker run -it --rm ubuntu:focal, it is going to be run on bash (/bin/bash).
Basically, you manually ran all your instructions on bash.
The easiest solution would be to use bash to run your instruction set because it already works as you tested.
You can simply instruct the docker to run all your instructions on bash using this command at the top:
SHELL ["/bin/bash", "-c"]
The changed Dockerfile will be:
FROM ubuntu:focal
SHELL ["/bin/bash", "-c"]
RUN ps -p $$
RUN ln -snf /usr/share/zoneinfo/Europe/Berlin /etc/localtime && echo Europe/Berlin > /etc/timezone \
&& apt-get update \
&& apt-get install -y git default-jdk-headless ant libcommons-lang3-java libbcprov-java \
&& git clone https://gitlab.com/pdftk-java/pdftk.git \
&& cd pdftk \
&& mkdir lib \
&& ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar \
&& ant jar
CMD ["java", "-jar", "/pdftk/build/jar/pdftk.jar"]
Hope this helps you. Cheers 🍻 !!!

Run Python scripts on command line running Docker images

I built a docker image using Dockerfile with Python and some libraries inside (no my project code inside). In my local work dir, there are some scripts to be run on the docker. So, here what I did
$ cd /path/to/my_workdir
$ docker run -it --name test -v `pwd`:`pwd` -w `pwd` my/code:test python src/main.py --config=test --results-dir=/home/me/Results
The command python src/main.py --config=test --results-dir=/home/me/Results is what I want to run inside the Docker container.
However, it returns,
/home/docker/miniconda3/bin/python: /home/docker/miniconda3/bin/python: cannot execute binary file
How can I fix it and run my code?
Here is my Dockerfile
FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04
MAINTAINER Me <me#me.com>
RUN apt update -yq && \
apt install -yq curl wget unzip git vim cmake sudo
RUN adduser --disabled-password --gecos '' docker && \
adduser docker sudo && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
WORKDIR /home/docker/
RUN chmod a+rwx /home/docker/ && \
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
bash Miniconda3-latest-Linux-x86_64.sh -b && rm Miniconda3-latest-Linux-x86_64.sh
ENV PATH /home/docker/miniconda3/bin:$PATH
Run pip install absl-py==0.5.0 atomicwrites==1.2.1 attrs==18.2.0 certifi==2018.8.24 chardet==3.0.4 cycler==0.10.0 docopt==0.6.2 enum34==1.1.6 future==0.16.0 idna==2.7 imageio==2.4.1 jsonpickle==1.2 kiwisolver==1.0.1 matplotlib==3.0.0 mock==2.0.0 more-itertools==4.3.0 mpyq==0.2.5 munch==2.3.2 numpy==1.15.2 pathlib2==2.3.2 pbr==4.3.0 Pillow==5.3.0 pluggy==0.7.1 portpicker==1.2.0 probscale==0.2.3 protobuf==3.6.1 py==1.6.0 pygame==1.9.4 pyparsing==2.2.2 pysc2==3.0.0 pytest==3.8.2 python-dateutil==2.7.3 PyYAML==3.13 requests==2.19.1 s2clientprotocol==4.10.1.75800.0 sacred==0.8.1 scipy==1.1.0 six==1.11.0 sk-video==1.1.10 snakeviz==1.0.0 tensorboard-logger==0.1.0 torch==0.4.1 torchvision==0.2.1 tornado==5.1.1 urllib3==1.23
USER docker
ENTRYPOINT ["/bin/bash"]
Try making the file executable before running it.
as John mentioned to do in the dockerfile
FROM python:latest
COPY src/main.py /usr/local/share/
RUN chmod +x /usr/local/share/src/main.py #<-**--- just add this also
# I have some doubts about the pathing
CMD ["/usr/local/share/src/main.py", "--config=test --results-dir=/home/me/Results"]
You can run a python script in docker by adding this to your docker file:
FROM python:latest
COPY src/main.py /usr/local/share/
CMD ["src/main.py", "--config=test --results-dir=/home/me/Results"]

python and oracle client on docker image

I want to create a docker image with oracle client and cx_oracle of python. I am using multi stage docker to build the image but I am missing an env variable due to which cx_oracle is not able to find an oracle client library.
FROM oraclelinux:7-slim
RUN curl -o /etc/yum.repos.d/public-yum-ol7.repo https://yum.oracle.com/public-yum-ol7.repo && \
yum-config-manager --enable ol7_oracle_instantclient && \
yum -y install oracle-instantclient18.3-basic oracle-instantclient18.3-devel oracle-instantclient18.3-sqlplus && \
rm -rf /var/cache/yum && \
echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient18.3.conf && \
ldconfig
ENV PATH=$PATH:/usr/lib/oracle/18.3/client64/bin
FROM python:slim
COPY ./requirement.txt ./requirement.txt
RUN pip install -r ./requirement.txt
COPY --from=0 /usr/lib/oracle/18.3/client64/lib /root/usr/lib/oracle/18.3/client64/lib
COPY --from=0 /usr/lib/oracle/18.3/client64/bin /root/usr/lib/oracle/18.3/client64/bin
ENV PATH=$PATH:/root/usr/lib/oracle/18.3/client64/bin:/root/usr/lib/oracle/18.3/client64/lib
ENV ORACLE_HOME=/root/usr/lib/oracle/18.3/client64/:$ORACLE_HOME
ENV LD_LIBRARY_PATH=/root/usr/lib/oracle/18.3/client64/:$LD_LIBRARY_PATH
RUN echo $PATH
RUN echo $ORACLE_HOME
RUN chmod 755 /root/usr/lib/oracle/18.3/client64/lib/*
RUN ls -l /root/usr/lib/oracle/18.3/client64/lib
CMD ["chmod","755","/root/usr/lib/oracle/18.3/client64/lib/*"]
CMD ["ls", "-l" ,"/root/usr/lib/oracle/18.3/client64/lib"]
CMD ["python","test.py"]
Below is the error
DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/odpi/doc/installation.html#linux
Oracle has Python Dockerfiles at https://github.com/oracle/docker-images/tree/main/OracleLinuxDevelopers
Also see https://blogs.oracle.com/opal/docker-for-oracle-database-applications-in-nodejs-and-python-part-1

Syntaxnet spec file and Docker?

I'm trying to learn Synatxnet. I have it running through Docker. But I really dont know much about either program Synatxnet or Docker. On the Github Sytaxnet page it says
The SyntaxNet models are configured via a combination of run-time
flags (which are easy to change) and a text format TaskSpec protocol
buffer. The spec file used in the demo is in
syntaxnet/models/parsey_mcparseface/context.pbtxt.
How exactly do I find the spec file to edit it?
I compiled SyntaxNet in a Docker container using these Instructions.
FROM java:8
ENV SYNTAXNETDIR=/opt/tensorflow PATH=$PATH:/root/bin
RUN mkdir -p $SYNTAXNETDIR \
&& cd $SYNTAXNETDIR \
&& apt-get update \
&& apt-get install git zlib1g-dev file swig python2.7 python-dev python-pip -y \
&& pip install --upgrade pip \
&& pip install -U protobuf==3.0.0b2 \
&& pip install asciitree \
&& pip install numpy \
&& wget https://github.com/bazelbuild/bazel/releases/download/0.2.2b/bazel-0.2.2b-installer-linux-x86_64.sh \
&& chmod +x bazel-0.2.2b-installer-linux-x86_64.sh \
&& ./bazel-0.2.2b-installer-linux-x86_64.sh --user \
&& git clone --recursive https://github.com/tensorflow/models.git \
&& cd $SYNTAXNETDIR/models/syntaxnet/tensorflow \
&& echo "\n\n\n" | ./configure \
&& apt-get autoremove -y \
&& apt-get clean
RUN cd $SYNTAXNETDIR/models/syntaxnet \
&& bazel test --genrule_strategy=standalone syntaxnet/... util/utf8/...
WORKDIR $SYNTAXNETDIR/models/syntaxnet
CMD [ "sh", "-c", "echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh" ]
# COMMANDS to build and run
# ===============================
# mkdir build && cp Dockerfile build/ && cd build
# docker build -t syntaxnet .
# docker run syntaxnet
First, comment out the command line in the dockerfile, then create and cd into an empty directory on your host machine. You can then create a container from the image, mounting a directory in the container to your hard-drive:
docker run -it --rm -v /pwd:/tmp bash
You'll now have a bash session in the container. Copy the spec file into /tmp from /opt/tensorflow/syntaxnet/models/parsey_mcparseface/context.pbtxt (I'm guessing that's where it is given the info you've provided above -- I can't get your dockerfile to build an image so I can't confirm it; you can always run find . -name context.pbtxt from root to find it), and exit the container (ctrl-d or exit).
You now have the file on your host's hd ready to edit, but you really want it in a running container. If the directory it comes from contains only that file, then you can simply mount your host directory at that path in the container. If it contains other things, then you can use a, so called, bootstrap script to move the file from your mounted directory (in the example above, that's tmp) to its home location. Alternatively, you may be able to tell the software where to find the spec file with a flag, but that will take more research.

Resources